mode7: more utils splitting

This commit is contained in:
Vince Weaver 2017-12-16 14:05:57 -05:00
parent ebd22ed243
commit b2cfa68e14
9 changed files with 425 additions and 422 deletions

50
asm_routines/gr_copy.s Normal file
View File

@ -0,0 +1,50 @@
;=========================================================
; gr_copy_to_current
;=========================================================
; copy 0xc00 to DRAW_PAGE
; 2 + 8*38 + 4*80*23 + 4*120*26 + 13 = 20,159 = 20ms = 50Hz
;
gr_copy_to_current:
ldx #0 ; set y to zero ; 2
gr_copy_loop:
stx TEMP ; save y ; 3
txa ; move to A ; 2
asl ; mult by 2 ; 2
tay ; put into Y ; 2
lda gr_offsets,Y ; lookup low byte for line addr ; 5
sta OUTL ; out and in are the same ; 3
sta INL ; 3
lda gr_offsets+1,Y ; lookup high byte for line addr ; 5
adc DRAW_PAGE
sta OUTH ; 3
lda gr_offsets+1,Y ; lookup high byte for line addr ; 5
adc #$8 ; for now, fixed 0xc ; 2
sta INH ; 3
ldx TEMP ; restore y ; 3
ldy #0 ; set X counter to 0 ; 2
gr_copy_line:
lda (INL),Y ; load a byte ; 5
sta (OUTL),Y ; store a byte ; 6
iny ; increment pointer ; 2
cpx #$4 ; don't want to copy bottom 4*40 ; 2
bcs gr_copy_above4 ; 3
gr_copy_below4:
cpy #120 ; for early ones, copy 120 bytes ; 2
bne gr_copy_line ; 3
beq gr_copy_line_done ; 3
gr_copy_above4: ; for last four, just copy 80 bytes
cpy #80 ; 2
bne gr_copy_line ; 3
gr_copy_line_done:
inx ; increment y value ; 2
cpx #8 ; there are 8 of them ; 2
bne gr_copy_loop ; if not, loop ; 3
rts ; 6

101
asm_routines/gr_putsprite.s Normal file
View File

@ -0,0 +1,101 @@
;=============================================
; put_sprite
;=============================================
; Sprite to display in INH,INL
; Location is XPOS,YPOS
; Note, only works if YPOS is multiple of two?
put_sprite:
ldy #0 ; byte 0 is xsize ; 2
lda (INL),Y ; 5
sta CH ; xsize is in CH ; 3
iny ; 2
lda (INL),Y ; byte 1 is ysize ; 5
sta CV ; ysize is in CV ; 3
iny ; 2
lda YPOS ; make a copy of ypos ; 3
sta TEMPY ; as we modify it ; 3
;===========
; 28
put_sprite_loop:
sty TEMP ; save sprite pointer ; 3
ldy TEMPY ; 3
lda gr_offsets,Y ; lookup low-res memory address ; 5
clc ; 2
adc XPOS ; add in xpos ; 3
sta OUTL ; store out low byte of addy ; 3
lda gr_offsets+1,Y ; look up high byte ; 5
adc DRAW_PAGE ; ; 3
sta OUTH ; and store it out ; 3
ldy TEMP ; restore sprite pointer ; 3
; OUTH:OUTL now points at right place
ldx CH ; load xsize into x ; 3
;===========
; 36
put_sprite_pixel:
lda (INL),Y ; get sprite colors ; 5
iny ; increment sprite pointer ; 2
sty TEMP ; save sprite pointer ; 3
ldy #$0 ; 2
; check if completely transparent
; if so, skip
cmp #$0 ; if all zero, transparent ; 2
beq put_sprite_done_draw ; don't draw it ; 2nt/3
; FIXME: use BIT? ;==============
; 17
sta COLOR ; save color for later ; 3
; check if top pixel transparent
and #$f0 ; check if top nibble zero ; 2
bne put_sprite_bottom ; if not skip ahead ; 2nt/3
lda #$f0 ; setup mask ; 2
sta MASK ; 3
bmi put_sprite_mask ; 2nt/3
put_sprite_bottom:
lda COLOR ; re-load color ; 3
and #$0f ; check if bottom nibble zero ; 2
bne put_sprite_all ; if not, skip ahead ; 2nt/3
lda #$0f ; 2
sta MASK ; setup mask ; 3
put_sprite_mask:
lda (OUTL),Y ; get color at output ; 5
and MASK ; mask off unneeded part ; 3
ora COLOR ; or the color in ; 3
sta (OUTL),Y ; store it back ; 5
jmp put_sprite_done_draw ; we are done ; 3
put_sprite_all:
lda COLOR ; load color ; 3
sta (OUTL),Y ; and write it out ; 5
put_sprite_done_draw:
ldy TEMP ; restore sprite pointer ; 3
inc OUTL ; increment output pointer ; 5
dex ; decrement x counter ; 2
bne put_sprite_pixel ; if not done, keep looping ; 2nt/3
inc TEMPY ; each line has two y vars ; 5
inc TEMPY ; 5
dec CV ; decemenet total y count ; 5
bne put_sprite_loop ; loop if not done ; 2nt/3
rts ; return ; 6

54
asm_routines/gr_vlin.s Normal file
View File

@ -0,0 +1,54 @@
;=========================================
; vlin
;=========================================
; X, V2 at Y
vlin:
sty TEMPY ; save Y (x location)
vlin_loop:
txa ; a=x (get first y)
and #$fe ; Clear bottom bit
tay ;
lda gr_offsets,Y ; lookup low-res memory address low
sta GBASL ; put it into our indirect pointer
iny
lda gr_offsets,Y ; lookup low-res memory address high
clc
adc DRAW_PAGE ; add in draw page offset
sta GBASH ; put into top of indirect
ldy TEMPY ; load back in y (x offset)
txa ; load back in x (current y)
lsr ; check the low bit
bcc vlin_low ; if not set, skip to low
vlin_high:
lda #$F0 ; setup masks
sta MASK
lda #$0f
bcs vlin_too_slow
vlin_low: ; setup masks
lda #$0f
sta MASK
lda #$f0
vlin_too_slow:
and (GBASL),Y ; mask current byte
sta (GBASL),Y ; and store back
lda MASK ; mask the color
and COLOR
ora (GBASL),Y ; or into the right place
sta (GBASL),Y ; store it
inx ; increment X (current y)
cpx V2 ; compare to the limit
bcc vlin_loop ; if <= then loop
rts ; return

111
asm_routines/keypress.s Normal file
View File

@ -0,0 +1,111 @@
;==========================================================
; Wait until keypressed
;==========================================================
;
wait_until_keypressed:
lda KEYPRESS ; check if keypressed
bpl wait_until_keypressed ; if not, loop
jmp figure_out_key
;==========================================================
; Get Key
;==========================================================
;
get_key:
check_paddle_button:
; check for paddle button
bit PADDLE_BUTTON0 ; 4
bpl no_button ; 2nt/3
lda #' '+128 ; 2
jmp save_key ; 3
no_button:
lda KEYPRESS ; 3
bpl no_key ; 2nt/3
figure_out_key:
cmp #' '+128 ; the mask destroys space ; 2
beq save_key ; so handle it specially ; 2nt/3
and #$5f ; mask, to make upper-case ; 2
check_right_arrow:
cmp #$15 ; 2
bne check_left_arrow ; 2nt/3
lda #'D' ; 2
check_left_arrow:
cmp #$08 ; 2
bne check_up_arrow ; 2nt/3
lda #'A' ; 2
check_up_arrow:
cmp #$0B ; 2
bne check_down_arrow ; 2nt/3
lda #'W' ; 2
check_down_arrow:
cmp #$0A ; 2
bne check_escape ; 2nt/3
lda #'S' ; 2
check_escape:
cmp #$1B ; 2
bne save_key ; 2nt/3
lda #'Q' ; 2
jmp save_key ; 3
no_key:
bit PADDLE_STATUS ; 3
bpl no_key_store ; 2nt/3
; check for paddle action
; code from http://web.pdx.edu/~heiss/technotes/aiie/tn.aiie.06.html
inc PADDLE_STATUS ; 5
lda PADDLE_STATUS ; 3
and #$03 ; 2
beq check_paddles ; 2nt/3
jmp no_key_store ; 3
check_paddles:
lda PADDLE_STATUS ; 3
and #$80 ; 2
sta PADDLE_STATUS ; 3
ldx #$0 ; 2
LDA PTRIG ;TRIGGER PADDLES ; 4
LDY #0 ;INIT COUNTER ; 2
NOP ;COMPENSATE FOR 1ST COUNT ; 2
NOP ; 2
PREAD2: LDA PADDL0,X ;COUNT EVERY 11 uSEC. ; 4
BPL RTS2D ;BRANCH WHEN TIMED OUT ; 2nt/3
INY ;INCREMENT COUNTER ; 2
BNE PREAD2 ;CONTINUE COUNTING ; 2nt/3
DEY ;COUNTER OVERFLOWED ; 2
RTS2D: ;RETURN W/VALUE 0-255
cpy #96 ; 2
bmi paddle_left ; 2nt/3
cpy #160 ; 2
bmi no_key_store ; 2nt/3
lda #'D' ; 2
jmp save_key ; 3
paddle_left:
lda #'A' ; 2
jmp save_key ; 3
no_key_store:
lda #0 ; no key, so save a zero ; 2
save_key:
sta LASTKEY ; save the key to our buffer ; 2
bit KEYRESET ; clear the keyboard buffer ; 4
rts ; 6
;============
; 33=nokey
; 48=worstkey

80
asm_routines/text_print.s Normal file
View File

@ -0,0 +1,80 @@
;================================
; htab_vtab
;================================
; move to CH/CV
htab_vtab:
lda CV
asl
tay
lda gr_offsets,Y ; lookup low-res memory address
clc
adc CH ; add in xpos
sta BASL ; store out low byte of addy
lda gr_offsets+1,Y ; look up high byte
adc DRAW_PAGE ;
sta BASH ; and store it out
; BASH:BASL now points at right place
rts
;================================
; move_and_print
;================================
; move to CH/CV
move_and_print:
jsr htab_vtab
;================================
; print_string
;================================
print_string:
ldy #0
print_string_loop:
lda (OUTL),Y
beq done_print_string
ora #$80
sta (BASL),Y
iny
bne print_string_loop
done_print_string:
rts
;====================
; point_to_end_string
;====================
point_to_end_string:
iny
tya
clc
adc OUTL
sta OUTL
lda #0
adc OUTH
sta OUTH
rts
;================================
; print_both_pages
;================================
print_both_pages:
lda DRAW_PAGE
pha
lda #0
sta DRAW_PAGE
jsr move_and_print
lda #4
sta DRAW_PAGE
jsr move_and_print
pla
sta DRAW_PAGE
rts ; oops forgot this initially
; explains the weird vertical stripes on the screen

View File

@ -1,418 +0,0 @@
;=====================================================================
;= ROUTINES
;=====================================================================
;==========================================================
; set_text_page0
;==========================================================
;
set_text_page0:
bit PAGE0 ; set page0
bit TEXT ; set text mode
rts
;==========================================================
; set_gr_page0
;==========================================================
;
set_gr_page0:
bit PAGE0 ; set page 0
bit LORES ; Lo-res graphics
bit TEXTGR ; mixed gr/text mode
bit SET_GR ; set graphics
rts
;=========================================================
; gr_copy_to_current
;=========================================================
; copy 0xc00 to DRAW_PAGE
; 2 + 8*38 + 4*80*23 + 4*120*26 + 13 = 20,159 = 20ms = 50Hz
;
gr_copy_to_current:
ldx #0 ; set y to zero ; 2
gr_copy_loop:
stx TEMP ; save y ; 3
txa ; move to A ; 2
asl ; mult by 2 ; 2
tay ; put into Y ; 2
lda gr_offsets,Y ; lookup low byte for line addr ; 5
sta OUTL ; out and in are the same ; 3
sta INL ; 3
lda gr_offsets+1,Y ; lookup high byte for line addr ; 5
adc DRAW_PAGE
sta OUTH ; 3
lda gr_offsets+1,Y ; lookup high byte for line addr ; 5
adc #$8 ; for now, fixed 0xc ; 2
sta INH ; 3
ldx TEMP ; restore y ; 3
ldy #0 ; set X counter to 0 ; 2
gr_copy_line:
lda (INL),Y ; load a byte ; 5
sta (OUTL),Y ; store a byte ; 6
iny ; increment pointer ; 2
cpx #$4 ; don't want to copy bottom 4*40 ; 2
bcs gr_copy_above4 ; 3
gr_copy_below4:
cpy #120 ; for early ones, copy 120 bytes ; 2
bne gr_copy_line ; 3
beq gr_copy_line_done ; 3
gr_copy_above4: ; for last four, just copy 80 bytes
cpy #80 ; 2
bne gr_copy_line ; 3
gr_copy_line_done:
inx ; increment y value ; 2
cpx #8 ; there are 8 of them ; 2
bne gr_copy_loop ; if not, loop ; 3
rts ; 6
;==========================================================
; Wait until keypressed
;==========================================================
;
wait_until_keypressed:
lda KEYPRESS ; check if keypressed
bpl wait_until_keypressed ; if not, loop
jmp figure_out_key
;==========================================================
; Get Key
;==========================================================
;
get_key:
check_paddle_button:
; check for paddle button
bit PADDLE_BUTTON0 ; 4
bpl no_button ; 2nt/3
lda #' '+128 ; 2
jmp save_key ; 3
no_button:
lda KEYPRESS ; 3
bpl no_key ; 2nt/3
figure_out_key:
cmp #' '+128 ; the mask destroys space ; 2
beq save_key ; so handle it specially ; 2nt/3
and #$5f ; mask, to make upper-case ; 2
check_right_arrow:
cmp #$15 ; 2
bne check_left_arrow ; 2nt/3
lda #'D' ; 2
check_left_arrow:
cmp #$08 ; 2
bne check_up_arrow ; 2nt/3
lda #'A' ; 2
check_up_arrow:
cmp #$0B ; 2
bne check_down_arrow ; 2nt/3
lda #'W' ; 2
check_down_arrow:
cmp #$0A ; 2
bne check_escape ; 2nt/3
lda #'S' ; 2
check_escape:
cmp #$1B ; 2
bne save_key ; 2nt/3
lda #'Q' ; 2
jmp save_key ; 3
no_key:
bit PADDLE_STATUS ; 3
bpl no_key_store ; 2nt/3
; check for paddle action
; code from http://web.pdx.edu/~heiss/technotes/aiie/tn.aiie.06.html
inc PADDLE_STATUS ; 5
lda PADDLE_STATUS ; 3
and #$03 ; 2
beq check_paddles ; 2nt/3
jmp no_key_store ; 3
check_paddles:
lda PADDLE_STATUS ; 3
and #$80 ; 2
sta PADDLE_STATUS ; 3
ldx #$0 ; 2
LDA PTRIG ;TRIGGER PADDLES ; 4
LDY #0 ;INIT COUNTER ; 2
NOP ;COMPENSATE FOR 1ST COUNT ; 2
NOP ; 2
PREAD2: LDA PADDL0,X ;COUNT EVERY 11 uSEC. ; 4
BPL RTS2D ;BRANCH WHEN TIMED OUT ; 2nt/3
INY ;INCREMENT COUNTER ; 2
BNE PREAD2 ;CONTINUE COUNTING ; 2nt/3
DEY ;COUNTER OVERFLOWED ; 2
RTS2D: ;RETURN W/VALUE 0-255
cpy #96 ; 2
bmi paddle_left ; 2nt/3
cpy #160 ; 2
bmi no_key_store ; 2nt/3
lda #'D' ; 2
jmp save_key ; 3
paddle_left:
lda #'A' ; 2
jmp save_key ; 3
no_key_store:
lda #0 ; no key, so save a zero ; 2
save_key:
sta LASTKEY ; save the key to our buffer ; 2
bit KEYRESET ; clear the keyboard buffer ; 4
rts ; 6
;============
; 33=nokey
; 48=worstkey
;=============================================
; put_sprite
;=============================================
; Sprite to display in INH,INL
; Location is XPOS,YPOS
; Note, only works if YPOS is multiple of two?
put_sprite:
ldy #0 ; byte 0 is xsize ; 2
lda (INL),Y ; 5
sta CH ; xsize is in CH ; 3
iny ; 2
lda (INL),Y ; byte 1 is ysize ; 5
sta CV ; ysize is in CV ; 3
iny ; 2
lda YPOS ; make a copy of ypos ; 3
sta TEMPY ; as we modify it ; 3
;===========
; 28
put_sprite_loop:
sty TEMP ; save sprite pointer ; 3
ldy TEMPY ; 3
lda gr_offsets,Y ; lookup low-res memory address ; 5
clc ; 2
adc XPOS ; add in xpos ; 3
sta OUTL ; store out low byte of addy ; 3
lda gr_offsets+1,Y ; look up high byte ; 5
adc DRAW_PAGE ; ; 3
sta OUTH ; and store it out ; 3
ldy TEMP ; restore sprite pointer ; 3
; OUTH:OUTL now points at right place
ldx CH ; load xsize into x ; 3
;===========
; 36
put_sprite_pixel:
lda (INL),Y ; get sprite colors ; 5
iny ; increment sprite pointer ; 2
sty TEMP ; save sprite pointer ; 3
ldy #$0 ; 2
; check if completely transparent
; if so, skip
cmp #$0 ; if all zero, transparent ; 2
beq put_sprite_done_draw ; don't draw it ; 2nt/3
; FIXME: use BIT? ;==============
; 17
sta COLOR ; save color for later ; 3
; check if top pixel transparent
and #$f0 ; check if top nibble zero ; 2
bne put_sprite_bottom ; if not skip ahead ; 2nt/3
lda #$f0 ; setup mask ; 2
sta MASK ; 3
bmi put_sprite_mask ; 2nt/3
put_sprite_bottom:
lda COLOR ; re-load color ; 3
and #$0f ; check if bottom nibble zero ; 2
bne put_sprite_all ; if not, skip ahead ; 2nt/3
lda #$0f ; 2
sta MASK ; setup mask ; 3
put_sprite_mask:
lda (OUTL),Y ; get color at output ; 5
and MASK ; mask off unneeded part ; 3
ora COLOR ; or the color in ; 3
sta (OUTL),Y ; store it back ; 5
jmp put_sprite_done_draw ; we are done ; 3
put_sprite_all:
lda COLOR ; load color ; 3
sta (OUTL),Y ; and write it out ; 5
put_sprite_done_draw:
ldy TEMP ; restore sprite pointer ; 3
inc OUTL ; increment output pointer ; 5
dex ; decrement x counter ; 2
bne put_sprite_pixel ; if not done, keep looping ; 2nt/3
inc TEMPY ; each line has two y vars ; 5
inc TEMPY ; 5
dec CV ; decemenet total y count ; 5
bne put_sprite_loop ; loop if not done ; 2nt/3
rts ; return ; 6
;================================
; htab_vtab
;================================
; move to CH/CV
htab_vtab:
lda CV
asl
tay
lda gr_offsets,Y ; lookup low-res memory address
clc
adc CH ; add in xpos
sta BASL ; store out low byte of addy
lda gr_offsets+1,Y ; look up high byte
adc DRAW_PAGE ;
sta BASH ; and store it out
; BASH:BASL now points at right place
rts
;================================
; move_and_print
;================================
; move to CH/CV
move_and_print:
jsr htab_vtab
;================================
; print_string
;================================
print_string:
ldy #0
print_string_loop:
lda (OUTL),Y
beq done_print_string
ora #$80
sta (BASL),Y
iny
bne print_string_loop
done_print_string:
rts
;====================
; point_to_end_string
;====================
point_to_end_string:
iny
tya
clc
adc OUTL
sta OUTL
lda #0
adc OUTH
sta OUTH
rts
;================================
; print_both_pages
;================================
print_both_pages:
lda DRAW_PAGE
pha
lda #0
sta DRAW_PAGE
jsr move_and_print
lda #4
sta DRAW_PAGE
jsr move_and_print
pla
sta DRAW_PAGE
rts ; oops forgot this initially
; explains the weird vertical stripes on the screen
;=========================================
; vlin
;=========================================
; X, V2 at Y
vlin:
sty TEMPY ; save Y (x location)
vlin_loop:
txa ; a=x (get first y)
and #$fe ; Clear bottom bit
tay ;
lda gr_offsets,Y ; lookup low-res memory address low
sta GBASL ; put it into our indirect pointer
iny
lda gr_offsets,Y ; lookup low-res memory address high
clc
adc DRAW_PAGE ; add in draw page offset
sta GBASH ; put into top of indirect
ldy TEMPY ; load back in y (x offset)
txa ; load back in x (current y)
lsr ; check the low bit
bcc vlin_low ; if not set, skip to low
vlin_high:
lda #$F0 ; setup masks
sta MASK
lda #$0f
bcs vlin_too_slow
vlin_low: ; setup masks
lda #$0f
sta MASK
lda #$f0
vlin_too_slow:
and (GBASL),Y ; mask current byte
sta (GBASL),Y ; and store back
lda MASK ; mask the color
and COLOR
ora (GBASL),Y ; or into the right place
sta (GBASL),Y ; store it
inx ; increment X (current y)
cpx V2 ; compare to the limit
bcc vlin_loop ; if <= then loop
rts ; return

View File

@ -23,21 +23,41 @@ MODE7_ISLAND: mode7_island.o
ld65 -o MODE7_ISLAND mode7_island.o -C ./apple2_1000.inc
mode7_island.o: mode7.s island_lookup.s island_map.inc \
fast_multiply.s utils.s zp.inc sprites.inc
fast_multiply.s zp.inc sprites.inc \
../asm_routines/hlin_clearscreen.s \
../asm_routines/pageflip.s \
../asm_routines/gr_setpage.s \
../asm_routines/keypress.s \
../asm_routines/gr_putsprite.s \
../asm_routines/text_print.s
ca65 -o mode7_island.o mode7.s -D ISLAND_MAP=1 -l mode7.lst
MODE7_CHECKERBOARD: mode7_checkerboard.o
ld65 -o MODE7_CHECKERBOARD mode7_checkerboard.o -C ./apple2_1000.inc
mode7_checkerboard.o: mode7.s checkerboard_lookup.s \
fast_multiply.s utils.s zp.inc sprites.inc
fast_multiply.s zp.inc sprites.inc \
fast_multiply.s zp.inc sprites.inc \
../asm_routines/hlin_clearscreen.s \
../asm_routines/pageflip.s \
../asm_routines/gr_setpage.s \
../asm_routines/keypress.s \
../asm_routines/gr_putsprite.s \
../asm_routines/text_print.s
ca65 -o mode7_checkerboard.o mode7.s -D CHECKERBOARD_MAP=1 -l mode7.lst
MODE7_RAINBOW: mode7_rainbow.o
ld65 -o MODE7_RAINBOW mode7_rainbow.o -C ./apple2_1000.inc
mode7_rainbow.o: mode7.s rainbow_lookup.s \
fast_multiply.s utils.s zp.inc sprites.inc
fast_multiply.s zp.inc sprites.inc \
fast_multiply.s zp.inc sprites.inc \
../asm_routines/hlin_clearscreen.s \
../asm_routines/pageflip.s \
../asm_routines/gr_setpage.s \
../asm_routines/keypress.s \
../asm_routines/gr_putsprite.s \
../asm_routines/text_print.s
ca65 -o mode7_rainbow.o mode7.s -D RAINBOW_MAP=1 -l mode7.lst
SCROLL_DEMO: scroll_demo.o

View File

@ -1096,7 +1096,12 @@ exit:
; External modules
;===============================================
.include "utils.s"
.include "../asm_routines/hlin_clearscreen.s"
.include "../asm_routines/pageflip.s"
.include "../asm_routines/gr_setpage.s"
.include "../asm_routines/keypress.s"
.include "../asm_routines/gr_putsprite.s"
.include "../asm_routines/text_print.s"
.include "sprites.inc"