Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "std/pseudoOps.asm"
- ;anti-clobbering single-depth subroutine technology
- #define L1ARG 0xea
- #define L1IRG 0xeb
- #define L1CRG 0xec
- #define L1RTA 0xee
- #define l1call_abs(_addr) /* only saves L&H */\
- stc_abs(L1CRG) /* save C (L&H) */ &&\
- ldc_imm(_addr) && jpr /* load subroutine address && jpr */ &&\
- ldc_abs(L1CRG) /* restore C */
- #define l1call_abs_s(_addr) \
- sta $,L1ARG /* save registers to L1_RG */ &&\
- sti $,L1IRG /* ^^ */ &&\
- stc_abs(L1CRG) /* ^^ */ &&\
- ldc_imm(_addr) && jpr /* load subroutine address && jpr there */ &&\
- ldi #,0 /* restore registers after returning */ &&\
- lda @,L1ARG /* ^^ */ &&\
- ldl @,L1CRG && ldh @,1+L1CRG /* ^^ */ &&\
- ldi @,L1IRG /* ^^ */
- #define l1prep stc_abs(L1RTA) //save return address for later
- #define l1rts ldc_abs(L1RTA) && jpr //retrieve return address and return
- ;used to actually call these subroutines
- #define adsb8s_16(_d,_val, _ptrA) \
- lda _d,(_val) && ldc_imm(_ptrA) &&\
- stc_abs(math_ptrA) &&\
- l1call_abs_s(_adsb8s_16)
- #define add16_16(_ptrA,_ptrB) \
- ldc_imm(_ptrA) && stc_abs(math_ptrA) &&\
- ldc_imm(_ptrB) &&\
- stc_abs(math_ptrB) &&\
- l1call_abs_s(_add16_16)
- ;.1*256 = 25.6 ~= 26
- ;vel and pos are fixed point numbers with 8 bits of fraction
- #define accel (.1*256)
- #define current_canvas 3
- ;pitch is how many pixels across the current canvas is
- #define pitch (16*2**current_canvas)
- #define vram_start (0x8000-pitch**2)
- ;program start
- set_canvas(#,current_canvas)
- jmp 0x200
- !@= 0x200 ;loop start
- ;key event velocity change
- get_key(#,'w') && bzs no_w ;if 'w' key pressed,
- adsb8s_16(#,-accel, vel_y) ;^^vel_y -= accel
- :no_w: get_key(#,'a') && bzs no_a ;if 'a' key pressed,
- adsb8s_16(#,-accel, vel_x) ;^^vel_x -= accel
- :no_a: get_key(#,'s') && bzs no_s ;if 's' key pressed,
- adsb8s_16(#,accel, vel_y) ;^^vel_y += accel
- :no_s: get_key(#,'d') && bzs no_d ;if 'd' key pressed,
- adsb8s_16(#,accel, vel_x) ;^^vel_x += accel
- :no_d:
- add16_16(pos_x_low, vel_x) ;add x velocity to x position
- add16_16(pos_y_low, vel_y) ;add y velocity to y position
- ldi #,0 ;set index register to 0
- lda @,pos_x ;put x&y into sprites' x&y
- sta $,amoog && sta $,amoog_flip ;^^
- lda @,pos_y ;^^
- sta $,amoog+1 && sta $,amoog_flip+1 ;^^
- lda #,0 ;set every pixel of canvas to palette color 0
- sys #,0x05 ;^^
- lda @,vel_x+1 && and #,0x80 ;if x velocity negative,
- bnz .f ;^^blit the horizontally-flipped sprite instead
- ldc_imm(amoog) && jmp .r ;^^
- .f: ldc_imm(amoog_flip) ;^^
- .r: sys #,0x06 ;^^(sys #6 blits the sprite at address C (L&H))
- ldh @,pos_x ;this doesn't do anything other than put
- ldl @,pos_y ;^^the position into L&H as a sort of debug print
- wait_frame
- jmp 0x200 ;go to start of loop
- :math_ptrA: !16 0 ;pointers that hold locations to operands
- :math_ptrB: !16 0 ;^^
- ;*ptrA += (signed)A
- :_adsb8s_16:
- ldi #,0 ;set index to 0 for low byte
- and #,0xff && bns .sub ;update n flag && branch to .sub if negative
- lda @,L1ARG ;restore original contents of A
- add *,math_ptrA && sta *,math_ptrA ;add A to low byte && store result
- ldi #,1 && lda *,math_ptrA ;set index to 1 for high byte && load high byte
- adc #,0 && sta *,math_ptrA ;if carry set, increment && store result
- jpr ;return from subroutine
- .sub: ;(remember, it's A-memory, not memory-A)
- lda @,L1ARG ;get two's complement of A
- xor #,0xff && add #,1 ;^^(to make sure we're not subtracting
- sta $,_SCRATCH_A ;^^ by a negative number)
- sec ;preemtively set carry flag so borrow isn't factored in
- lda *,math_ptrA ;get low byte of 16-bit number
- sbc @,_SCRATCH_A && sta *,math_ptrA ;subtract low byte by A && store result
- bcs .r ;if no borrow, then skip decrement
- ldi #,1 && lda *,math_ptrA ;set index to 1 for high byte && load high byte
- add #,-1 && sta *,math_ptrA ;decrement high byte && store result
- ;^^'add -1' instead of 'sec && sbc 1' so carry flag is ignored
- .r: jpr ;return from subroutine
- ;*ptrA += *ptrB
- :_add16_16:
- ldi #,0 && lda *,math_ptrA ;set index to 0 for low byte && load low byte
- add *,math_ptrB && sta *,math_ptrA ;add low bytes && store result
- ldi #,1 && lda *,math_ptrA ;set index to 1 for high byte && load high byte
- adc *,math_ptrB && sta *,math_ptrA ;add high bytes (+carry bit) && store result
- jpr ;return from subroutine
- ;pitch/2-(w or h)/2 = centered
- :pos_x_low: !8 0 && :pos_x: !8 pitch/2-4
- :pos_y_low: !8 0 && :pos_y: !8 pitch/2-4
- :vel_x: !16 0 && :vel_y: !16 0
- #define rd 196 //palette color red
- #define bl 80 //palette color blue
- #define wh 231 //palette color white
- ;x,y, w,h, pixel data...
- :amoog: !8 0,0, 8,8
- !8 0, 0,rd,rd,rd,rd,rd,rd
- !8 0, 0,rd,rd,rd,rd,rd,rd
- !8 rd,rd,rd,rd,bl,wh,wh,wh
- !8 rd,rd,rd,rd,bl,bl,bl,bl
- !8 rd,rd,rd,rd,rd,rd,rd,rd
- !8 rd,rd,rd,rd,rd,rd,rd,rd
- !8 0, 0,rd,rd, 0, 0,rd,rd
- !8 0, 0,rd,rd, 0, 0,rd,rd
- :amoog_flip: !8 0,0, 8,8
- !8 rd,rd,rd,rd,rd,rd, 0, 0
- !8 rd,rd,rd,rd,rd,rd, 0, 0
- !8 wh,wh,wh,bl,rd,rd,rd,rd
- !8 bl,bl,bl,bl,rd,rd,rd,rd
- !8 rd,rd,rd,rd,rd,rd,rd,rd
- !8 rd,rd,rd,rd,rd,rd,rd,rd
- !8 rd,rd, 0, 0,rd,rd, 0, 0
- !8 rd,rd, 0, 0,rd,rd, 0, 0
- !savlbl "labels.txt" && !to "program.bin" && !save
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement