From 8001a35f5c6f484275ccd42b20de5194fa4b8384 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 28 Dec 2020 01:11:54 -0500 Subject: [PATCH] tfv: modernize and split up title screen from rest still lots of work to do --- duke/TODO | 6 +- duke/zp.inc | 2 +- tfv/Makefile | 43 +- tfv/common_defines.inc | 3 + tfv/gr_copy.s | 161 ++++ tfv/gr_fast_clear.s | 6 + tfv/gr_offsets.s | 5 + tfv/gr_pageflip.s | 24 + tfv/gr_vlin.s | 54 ++ tfv/graphics_map/Makefile | 3 +- tfv/graphics_title/Makefile | 19 + .../title.piskel | 0 .../title.png | Bin tfv/loader.s | 709 ++++++++++++++++++ tfv/text_print.s | 191 +++++ tfv/tfv.s | 35 +- tfv/tfv_opener.s | 17 +- tfv/tfv_title.s | 80 ++ tfv/wait_keypressed.s | 6 + tfv/{tfv_zp.inc => zp.inc} | 155 ++-- 20 files changed, 1357 insertions(+), 162 deletions(-) create mode 100644 tfv/common_defines.inc create mode 100644 tfv/gr_copy.s create mode 100644 tfv/gr_offsets.s create mode 100644 tfv/gr_pageflip.s create mode 100644 tfv/gr_vlin.s create mode 100644 tfv/graphics_title/Makefile rename tfv/{graphics_map => graphics_title}/title.piskel (100%) rename tfv/{graphics_map => graphics_title}/title.png (100%) create mode 100644 tfv/loader.s create mode 100644 tfv/text_print.s create mode 100644 tfv/wait_keypressed.s rename tfv/{tfv_zp.inc => zp.inc} (55%) diff --git a/duke/TODO b/duke/TODO index 51460703..47b9af16 100644 --- a/duke/TODO +++ b/duke/TODO @@ -7,11 +7,7 @@ Major Issues + Better sound effects + Enemy movement/AI + Ability to take damage - - - - - ++ Have duke not be drawn if going into exit sound: diff --git a/duke/zp.inc b/duke/zp.inc index e4516098..79c4e7db 100644 --- a/duke/zp.inc +++ b/duke/zp.inc @@ -178,7 +178,7 @@ OUTH = $FF ; read any file slot 6 version ; based on FASTLD6 and RTS copyright (c) Peter Ferrie 2011-2013,2018 -; modified to assembled with ca64 -- vmw +; modified to assemble with ca65 -- vmw ; added code to patch it to run from current disk slot -- vmw diff --git a/tfv/Makefile b/tfv/Makefile index f6550945..75b975b9 100644 --- a/tfv/Makefile +++ b/tfv/Makefile @@ -11,21 +11,44 @@ all: tfv.dsk $(DOS33): cd ../dos33fs-utils && make -tfv.dsk: $(DOS33) TFV HELLO +tfv.dsk: $(DOS33) HELLO LOADER TFV_TITLE TFV $(DOS33) -y tfv.dsk SAVE A HELLO - $(DOS33) -y tfv.dsk BSAVE -a 0x1000 TFV -# $(DOS33) -y tfv.dsk BSAVE -a 0x2000 HIGHWIND.ED -# $(DOS33) -y tfv.dsk BSAVE -a 0x2000 FIGHTING.ED + $(DOS33) -y tfv.dsk BSAVE -a 0x1000 LOADER + $(DOS33) -y tfv.dsk BSAVE -a 0x2000 TFV_TITLE + $(DOS33) -y tfv.dsk BSAVE -a 0x2000 TFV + +### + +HELLO: hello.bas + ../asoft_basic-utils/tokenize_asoft < hello.bas > HELLO + +#### + +LOADER: loader.o + ld65 -o LOADER loader.o -C ../linker_scripts/apple2_1000.inc + +loader.o: loader.s init_vars.s common_defines.inc + ca65 -o loader.o loader.s -l loader.lst + +### + +TFV_TITLE: tfv_title.o + ld65 -o TFV_TITLE tfv_title.o -C ../linker_scripts/apple2_2000.inc + +tfv_title.o: tfv_title.s \ + gr_vlin.s tfv_opener.s \ + graphics_title/tfv_title.inc + ca65 -o tfv_title.o tfv_title.s -l tfv_title.lst ### TFV: tfv.o - ld65 -o TFV tfv.o -C ../linker_scripts/apple2_1000.inc + ld65 -o TFV tfv.o -C ../linker_scripts/apple2_2000.inc tfv.o: tfv.s \ - tfv_flying.s tfv_info.s tfv_opener.s tfv_title.s \ + tfv_flying.s tfv_info.s \ tfv_textentry.s tfv_worldmap.s \ - graphics_map/tfv_backgrounds.inc tfv_sprites.inc tfv_zp.inc \ + graphics_map/tfv_backgrounds.inc tfv_sprites.inc zp.inc \ ../asm_routines/multiply_fast.s \ gr_fast_clear.s \ ../asm_routines/pageflip.s \ @@ -42,14 +65,10 @@ tfv.o: tfv.s \ graphics_map/tfv_backgrounds.inc: cd graphics_map && make -### - -HELLO: hello.bas - ../asoft_basic-utils/tokenize_asoft < hello.bas > HELLO ### clean: - rm -f *~ TITLE.GR *.o *.lst ED TFV + rm -f *~ TITLE.GR *.o *.lst TFV TFV_TITLE HELLO LOADER diff --git a/tfv/common_defines.inc b/tfv/common_defines.inc new file mode 100644 index 00000000..6090170e --- /dev/null +++ b/tfv/common_defines.inc @@ -0,0 +1,3 @@ +LOAD_TITLE = 0 +LOAD_TFV = 1 +LOAD_FLYING = 2 diff --git a/tfv/gr_copy.s b/tfv/gr_copy.s new file mode 100644 index 00000000..a657400b --- /dev/null +++ b/tfv/gr_copy.s @@ -0,0 +1,161 @@ + ;========================================================= + ; gr_copy_to_current, 40x48 version + ;========================================================= + ; copy 0xc00 to DRAW_PAGE + ; + ; 45 + 2 + 120*(8*9 + 5) -1 + 6 = 9292 +;.align $100 +gr_copy_to_current: + + lda DRAW_PAGE ; 3 + clc ; 2 + adc #$4 ; 2 + sta gr_copy_line+5 ; 4 + sta gr_copy_line+11 ; 4 + adc #$1 ; 2 + sta gr_copy_line+17 ; 4 + sta gr_copy_line+23 ; 4 + adc #$1 ; 2 + sta gr_copy_line+29 ; 4 + sta gr_copy_line+35 ; 4 + adc #$1 ; 2 + sta gr_copy_line+41 ; 4 + sta gr_copy_line+47 ; 4 + ;=========== + ; 45 + + ldy #119 ; for early ones, copy 120 bytes ; 2 + +gr_copy_line: + lda $C00,Y ; load a byte (self modified) ; 4 + sta $400,Y ; store a byte (self modified) ; 5 + + lda $C80,Y ; load a byte (self modified) ; 4 + sta $480,Y ; store a byte (self modified) ; 5 + + lda $D00,Y ; load a byte (self modified) ; 4 + sta $500,Y ; store a byte (self modified) ; 5 + + lda $D80,Y ; load a byte (self modified) ; 4 + sta $580,Y ; store a byte (self modified) ; 5 + + lda $E00,Y ; load a byte (self modified) ; 4 + sta $600,Y ; store a byte (self modified) ; 5 + + lda $E80,Y ; load a byte (self modified) ; 4 + sta $680,Y ; store a byte (self modified) ; 5 + + lda $F00,Y ; load a byte (self modified) ; 4 + sta $700,Y ; store a byte (self modified) ; 5 + + lda $F80,Y ; load a byte (self modified) ; 4 + sta $780,Y ; store a byte (self modified) ; 5 + + dey ; decrement pointer ; 2 + bpl gr_copy_line ; ; 2nt/3 + + rts ; 6 + + + + ;========================================================= + ; gr_copy_to_current, 40x48 version + ;========================================================= + ; copy 0x1000 to DRAW_PAGE + +gr_copy_to_current_1000: + + lda DRAW_PAGE ; 3 + clc ; 2 + adc #$4 ; 2 + sta gr_copy_line_40+5 ; 4 + sta gr_copy_line_40+11 ; 4 + adc #$1 ; 2 + sta gr_copy_line_40+17 ; 4 + sta gr_copy_line_40+23 ; 4 + adc #$1 ; 2 + sta gr_copy_line_40+29 ; 4 + sta gr_copy_line_40+35 ; 4 + adc #$1 ; 2 + sta gr_copy_line_40+41 ; 4 + sta gr_copy_line_40+47 ; 4 + ;=========== + ; 45 + + ldy #119 ; for early ones, copy 120 bytes ; 2 + +gr_copy_line_40: + lda $1000,Y ; load a byte (self modified) ; 4 + sta $400,Y ; store a byte (self modified) ; 5 + + lda $1080,Y ; load a byte (self modified) ; 4 + sta $480,Y ; store a byte (self modified) ; 5 + + lda $1100,Y ; load a byte (self modified) ; 4 + sta $500,Y ; store a byte (self modified) ; 5 + + lda $1180,Y ; load a byte (self modified) ; 4 + sta $580,Y ; store a byte (self modified) ; 5 + + lda $1200,Y ; load a byte (self modified) ; 4 + sta $600,Y ; store a byte (self modified) ; 5 + + lda $1280,Y ; load a byte (self modified) ; 4 + sta $680,Y ; store a byte (self modified) ; 5 + + lda $1300,Y ; load a byte (self modified) ; 4 + sta $700,Y ; store a byte (self modified) ; 5 + + lda $1380,Y ; load a byte (self modified) ; 4 + sta $780,Y ; store a byte (self modified) ; 5 + + dey ; decrement pointer ; 2 + bpl gr_copy_line_40 ; ; 2nt/3 + + rts ; 6 + + + + ;========================================================= + ; gr_copy_to_current_40x40 + ;========================================================= + ; Take image in 0xc00 + ; Copy to DRAW_PAGE + ; Actually copy lines 0..39 + ; Don't over-write bottom 4 lines of text +gr_copy_to_current_40x40: + + ldx #0 +gc_40x40_loop: + lda gr_offsets,x + sta OUTL + sta INL + lda gr_offsets+1,x + clc + adc DRAW_PAGE + sta OUTH + + lda gr_offsets+1,x + clc + adc #$8 + sta INH + + ldy #39 +gc_40x40_inner: + lda (INL),Y + sta (OUTL),Y + + dey + bpl gc_40x40_inner + + inx + inx + + cpx #40 + bne gc_40x40_loop + + rts ; 6 + + + + diff --git a/tfv/gr_fast_clear.s b/tfv/gr_fast_clear.s index 8cc8d152..a86eb105 100644 --- a/tfv/gr_fast_clear.s +++ b/tfv/gr_fast_clear.s @@ -3,6 +3,9 @@ clear_screens: ; Clear top/bottom of page 0 ;=================================== + lda DRAW_PAGE + pha + lda #$0 sta DRAW_PAGE jsr clear_top @@ -17,6 +20,9 @@ clear_screens: jsr clear_top jsr clear_bottom + pla + sta DRAW_PAGE + rts diff --git a/tfv/gr_offsets.s b/tfv/gr_offsets.s new file mode 100644 index 00000000..d3af91f7 --- /dev/null +++ b/tfv/gr_offsets.s @@ -0,0 +1,5 @@ +gr_offsets: + .word $400,$480,$500,$580,$600,$680,$700,$780 + .word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8 + .word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0 + diff --git a/tfv/gr_pageflip.s b/tfv/gr_pageflip.s new file mode 100644 index 00000000..f199f5be --- /dev/null +++ b/tfv/gr_pageflip.s @@ -0,0 +1,24 @@ + ;========== + ; page_flip + ;========== + +page_flip: + lda DISP_PAGE ; 3 + beq page_flip_show_1 ; 2nt/3 +page_flip_show_0: + bit PAGE0 ; 4 + lda #4 ; 2 + sta DRAW_PAGE ; DRAW_PAGE=1 ; 3 + lda #0 ; 2 + sta DISP_PAGE ; DISP_PAGE=0 ; 3 + rts ; 6 +page_flip_show_1: + bit PAGE1 ; 4 + sta DRAW_PAGE ; DRAW_PAGE=0 ; 3 + lda #1 ; 2 + sta DISP_PAGE ; DISP_PAGE=1 ; 3 + rts ; 6 + ;==================== + ; DISP_PAGE=0 26 + ; DISP_PAGE=1 24 + diff --git a/tfv/gr_vlin.s b/tfv/gr_vlin.s new file mode 100644 index 00000000..0e2bef80 --- /dev/null +++ b/tfv/gr_vlin.s @@ -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 + + diff --git a/tfv/graphics_map/Makefile b/tfv/graphics_map/Makefile index d6e334bc..4d24e887 100644 --- a/tfv/graphics_map/Makefile +++ b/tfv/graphics_map/Makefile @@ -5,11 +5,10 @@ PNG2GR = ../../gr-utils/png2gr LZSA = ~/research/lzsa/lzsa/lzsa tfv_backgrounds.inc: \ - title.lzsa map.lzsa landing.lzsa harfco.lzsa \ + map.lzsa landing.lzsa harfco.lzsa \ belair.lzsa math_office.lzsa video_hr.lzsa \ collegep.lzsa umcp.lzsa dining.lzsa metro.lzsa \ talbot.lzsa - echo "title_lzsa: .incbin \"title.lzsa\"" > tfv_backgrounds.inc echo "map_lzsa: .incbin \"map.lzsa\"" >> tfv_backgrounds.inc echo "landing_lzsa: .incbin \"landing.lzsa\"" >> tfv_backgrounds.inc echo "harfco_lzsa: .incbin \"harfco.lzsa\"" >> tfv_backgrounds.inc diff --git a/tfv/graphics_title/Makefile b/tfv/graphics_title/Makefile new file mode 100644 index 00000000..6a640e3d --- /dev/null +++ b/tfv/graphics_title/Makefile @@ -0,0 +1,19 @@ +include ../../Makefile.inc + +PNG2RLE = ../../gr-utils/png2rle +PNG2GR = ../../gr-utils/png2gr +LZSA = ~/research/lzsa/lzsa/lzsa + +tfv_title.inc: \ + title.lzsa + echo "title_lzsa: .incbin \"title.lzsa\"" > tfv_title.inc + +%.gr: %.png + $(PNG2GR) $< $@ + +%.lzsa: %.gr + $(LZSA) -r -f2 $< $@ + +clean: + rm -f *~ tfv_title.inc + diff --git a/tfv/graphics_map/title.piskel b/tfv/graphics_title/title.piskel similarity index 100% rename from tfv/graphics_map/title.piskel rename to tfv/graphics_title/title.piskel diff --git a/tfv/graphics_map/title.png b/tfv/graphics_title/title.png similarity index 100% rename from tfv/graphics_map/title.png rename to tfv/graphics_title/title.png diff --git a/tfv/loader.s b/tfv/loader.s new file mode 100644 index 00000000..f019cba6 --- /dev/null +++ b/tfv/loader.s @@ -0,0 +1,709 @@ +; Loader for DUKE + +.include "zp.inc" +.include "hardware.inc" +.include "common_defines.inc" + +nibtbl = $300 ; nothing uses the bottom 128 bytes of $300, do they? +bit2tbl = $380 ; bit2tbl: .res 86 ; = nibtbl+128 +filbuf = $3D6 ; filbuf: .res 4 ; = bit2tbl+86 + +; read any file slot 6 version +; based on FASTLD6 and RTS copyright (c) Peter Ferrie 2011-2013,2018 + +; modified to assembled with ca65 -- vmw +; added code to patch it to run from current disk slot -- vmw + +; WHICH_LOAD = $7E ; thing to load +; adrlo = $26 ; constant from boot prom +; adrhi = $27 ; constant from boot prom +; tmpsec = $3c ; constant from boot prom +; reqsec = $3d ; constant from boot prom +; sizelo = $44 +; sizehi = $45 +; secsize = $46 +; namlo = $f8 +; namhi = $f9 +; TEMPY = $fa +; step = $fd ; state for stepper motor +; tmptrk = $fe ; temporary copy of current track +; phase = $ff ; current phase for /seek +; OUTL = $fe ; for picking filename +; OUTH = $ff + + dirbuf = $c00 + ; note, don't put this immediately below + ; the value being read as destaddr-4 + ; is temporarily overwritten during read + ; process + + + FILENAME = $280 + + ;=================================================== + ;=================================================== + ; START / INIT + ;=================================================== + ;=================================================== + +loader_start: + + lda #LOAD_TITLE + sta WHICH_LOAD + + jsr init ; unhook DOS, init nibble table + + + ;=================================================== + ;=================================================== + ; SETUP THE FILENAME + ;=================================================== + ;=================================================== + +which_load_loop: + + + + ; update the which-file error message +; lda WHICH_LOAD +; tay +; lda which_disk,Y +; sta error_string+19 + + lda WHICH_LOAD + asl + + tay + lda filenames,Y + sta OUTL + lda filenames+1,Y + sta OUTH + + lda WHICH_LOAD + bne load_other + +load_intro: + lda #<$2000 + sta entry_smc+1 + lda #>$2000 + sta entry_smc+2 + jmp actual_load + +load_other: + lda #<$2000 + sta entry_smc+1 + lda #>$2000 + sta entry_smc+2 + +actual_load: + + ;=================================================== + ;=================================================== + ; SET UP DOS3.3 FILENAME + ;=================================================== + ;=================================================== + +load_file_and_execute: + + jsr opendir_filename + +entry_smc: + jsr $1000 ; jump to common entry point + + ; hope they updated the WHICH_LOAD value + + jmp which_load_loop + + + ;============================== + ; setup filename then open/load + +opendir_filename: + + ; clear out the filename with $A0 (space) + + lda #FILENAME + sta namhi + + ldy #29 +wipe_filename_loop: + lda #$A0 + sta (namlo),Y + dey + bpl wipe_filename_loop + + ldy #0 +copy_filename_loop: + lda (OUTL),Y + beq copy_filename_done + ora #$80 + sta (namlo),Y + iny + bne copy_filename_loop + +copy_filename_done: + jsr opendir ; open and read entire file into memory + + rts + +filenames: + .word intro_filename + .word flying_filename + .word duke2_filename + +intro_filename: + .byte "TFV_TITLE",0 +flying_filename: + .byte "TFV_FLYING",0 +duke2_filename: + .byte "DUKE_LEVEL2",0 + + + ;=================================================== + ;=================================================== + ; INIT (build nibble table) + ;=================================================== + ;=================================================== + + ;unhook DOS and build nibble table + +init: + ; patch to use current drive + + ; locate input paramater list + jsr $3E3 + ; result is in A:Y + sta $FF + sty $FE + ldy #1 + lda ($FE),y + + ; list+1 should have slot<<8 + + + ora #$80 ; add in $80 + + ; c0e0 + sta mlsmc06+1 + + ; c0e8 + clc + adc #8 + sta mlsmc02+1 + sta mlsmc07+1 + + ; c0e9 + clc + adc #1 + sta mlsmc01+1 + + ; c0ec + clc + adc #3 + sta mlsmc03+1 + sta mlsmc04+1 + sta mlsmc05+1 + + jsr $fe93 ; clear COUT + jsr $fe89 ; clear KEYIN + + ;======================== + ; Create nibble table + ; Note: the table starts 16 bytes in, and is sparse + ; so it doesn't entirely look like the DOS33 table at + + ldy #0 + ldx #3 +L1: stx $3c ; store tempx (3?) + txa ; a=x (a=3) + asl ; a*=2 (a=6) + bit $3c ; a&tempx, set N/V (a=6) + beq L3 ; if 0, skip to L3 + ora $3c ; a|=tempx (a=7) + eor #$ff ; a=~a (a=f8) + and #$7e ; a&=0x7e 0111 1110 (a=78) +L2: bcs L3 ; this set way back at asl?? + lsr ; a>>1 a=3c c=0 + ; a=1e c=0 + ; a=0f c=0 + ; a=07 c=1 + bne L2 ; if a!=0 goto l2 + tya ; if a==0, a=y + sta nibtbl, x ; write out to table + iny ; increment y +L3: inx ; increment x x=4, a=0f + bpl L1 ; loop while high bit not set + + rts + + + ;=================================================== + ;=================================================== + ; file not found + ;=================================================== + ;=================================================== + +file_not_found: + +mlsmc07:lda $c0e8 ; turn off drive motor? + + jsr TEXT + jsr HOME + + ldy #0 + + lda #error_string + sta OUTH + +quick_print: + lda (OUTL),Y + beq quick_print_done + jsr COUT1 + iny + jmp quick_print + +quick_print_done: +; rts + +; jsr quick_print + +fnf_keypress: + lda KEYPRESS + bpl fnf_keypress + bit KEYRESET + + jmp which_load_loop + +; offset for disk number is 19 +error_string: +.byte "PLEASE INSERT DISK 1, PRESS RETURN",0 + + + + + + ;=================================================== + ;=================================================== + ; OPENDIR: actually load the file + ;=================================================== + ;=================================================== + + ; turn on drive and read volume table of contents +opendir: +mlsmc01:lda $c0e9 ; turn slot#6 drive on + ldx #0 + stx adrlo ; zero out adrlo + stx secsize ; zero out secsize + lda #$11 ; a=$11 (VTOC) + jsr readdirsec +firstent: + + lda dirbuf+1 + + ; lock if entry not found +entry_not_found: + beq file_not_found + + ; read directory sector + + ldx dirbuf+2 + jsr seekread1 + ldy #7 ;number of directory entries in a sector + ldx #$2b ;offset of filename in directory entry +nextent: + tya + pha ; was **phy** + txa + pha ; was **phx** + ldy #$1d + + ; match name backwards (slower but smaller) + +L4: + lda (namlo), y + cmp dirbuf, x + beq foundname + pla + + ; move to next directory in this block, if possible + + clc + adc #$23 + tax + pla + tay ; was **ply** + dey + bne nextent + beq firstent ; was **bra** + +foundname: + dex + dey + bpl L4 + pla + tay ; was **ply** + pla + + ; read track/sector list + + lda dirbuf-32, y + ldx dirbuf-31, y + jsr seekread1 + + ; read load offset and length info only, initially + + lda #filbuf + jsr seekread + + ; reduce load offset by 4, to account for offset and length + + sec + lda filbuf + sbc #4 + sta adrlo + + lda filbuf+1 + sbc #0 + sta adrhi + + ; save on stack bytes that will be overwritten by extra read + + ldy #3 +L5: + lda (adrlo), y + pha + dey + bpl L5 + + lda adrhi + pha + lda adrlo + pha + + ; increase load size by 4, to account for offst and length + + lda filbuf+2 + adc #3 + sta sizelo + sta secsize + + lda filbuf+3 + adc #0 + sta sizehi + beq readfirst + lda #0 ; was **stz secsize** + sta secsize + +readfirst: + ldy #$0c + + ; read a file sector + +readnext: + tya + pha + lda dirbuf, y ; A = track + ldx dirbuf+1, y ; x = sector + jsr seekread1 + pla + tay + + ; if low count is non-zero then we are done + ; (can happen only for partial last block) + + lda secsize + bne readdone + + ; continue if more than $100 bytes left + + dec sizehi + bne L6 + + ; set read size to min(length, $100) + + lda sizelo + beq readdone + sta secsize +L6: + inc adrhi + iny + iny + bne readnext + + ; save current address for after t/s read + + lda adrhi + pha + lda adrlo + pha + lda #0 + sta adrlo ; was **stz adrlo** + + ; read next track/sector sector + + lda dirbuf+1 + ldx dirbuf+2 + jsr readdirsec + clc + + ; restore current address +readdone: + pla + sta adrlo ; code originally had this backwards + pla + sta adrhi + bcc readfirst + +mlsmc02:lda $c0e8 + + ; restore from stack bytes that were overwritten by extra read + + ldx #3 + ldy #0 +L7: + pla + sta (adrlo), y + iny + dex + bpl L7 + rts + + + ;====================== + ; readdirsec + ;====================== + ; a = track? + ; x = sector? +readdirsec: + ldy #>dirbuf +seekread: + sty adrhi +seekread1: + sta phase + lda sectbl, x + sta reqsec + jsr readadr + + ; if track does not match, then seek + + cpx phase + beq checksec + jsr seek + + + ;========================================= + ; re merge in with qkumba's recent changes + ; to fix seek problem? + ;========================================= + + ; [re-]read sector + +re_read_addr: + jsr readadr +checksec: + cmp reqsec + bne re_read_addr + + ;========================= + ; read sector data + ;========================= + +readdata: + jsr readd5aa + eor #$ad ; zero A if match + bne re_read_addr + +L12: +mlsmc03:ldx $c0ec ; read until valid data (high bit set) + bpl L12 + eor nibtbl-$80, x + sta bit2tbl-$aa, y + iny + bne L12 +L13: +mlsmc04:ldx $c0ec ; read until valid data (high bit set) + bpl L13 + eor nibtbl-$80, x + sta (adrlo), y ; the real address + iny + cpy secsize + bne L13 + ldy #0 +L14: + ldx #$a9 +L15: + inx + beq L14 + lda (adrlo), y + lsr bit2tbl-$aa, x + rol + lsr bit2tbl-$aa, x + rol + sta (adrlo), y + iny + cpy secsize + bne L15 + rts + + ; no tricks here, just the regular stuff + + ;======================= + ; readaddr -- read the address field + ;======================= + ; Find address field, put track in cutrk, sector in tmpsec + +readadr: + jsr readd5aa + cmp #$96 + bne readadr + ldy #3 ; three? + ; first read volume/volume + ; then track/track + ; then sector/sector? +adr_read_two_bytes: + tax + jsr readnib + rol + sta tmpsec + jsr readnib + and tmpsec + dey + bne adr_read_two_bytes + rts + + ;======================== + ; make sure we see the $D5 $AA pattern + +readd5aa: +L16: + jsr readnib +L17: + cmp #$d5 + bne L16 + jsr readnib + cmp #$aa + bne L17 + tay ; we need Y=#$AA later + +readnib: +mlsmc05:lda $c0ec ; read until valid (high bit set) + bpl readnib + +seekret: + rts + + ;===================== + ; SEEK + ;===================== + ; current track in X? + ; desired track in phase + +seek: + ldy #0 + sty step + asl phase ; multiply by two + txa ; current track? + asl ; mul by two +copy_cur: + tax + sta tmptrk + sec + sbc phase + beq L22 + bcs L18 + eor #$ff + inx + bcc L19 +L18: + sbc #1 + dex +L19: + cmp step + bcc L20 + lda step +L20: + cmp #8 + bcs L21 + tay + sec +L21: + txa + pha + ldx step1, y +L22: + php + bne L24 +L23: + clc + lda tmptrk + ldx step2, y +L24: + stx tmpsec + and #3 + rol + tax + lsr +mlsmc06:lda $c0e0, x +L25: + ldx #$12 +L26: + dex + bpl L26 + dec tmpsec + bne L25 + bcs L23 + plp + beq seekret + pla + inc step + bne copy_cur + + + +step1: .byte $01, $30, $28, $24, $20, $1e, $1d, $1c +step2: .byte $70, $2c, $26, $22, $1f, $1e, $1d, $1c + +sectbl: .byte $00,$0d,$0b,$09,$07,$05,$03,$01,$0e,$0c,$0a,$08,$06,$04,$02,$0f + + +; From $BA96 of DOS33 +;nibtbl: .res 128 ; = * +; .byte $00,$01,$98,$99,$02,$03,$9C,$04 ; $BA96 ; 00 +; .byte $05,$06,$A0,$A1,$A2,$A4,$A4,$A5 ; $BA9E ; 08 +; .byte $07,$08,$A8,$A9,$AA,$09,$0A,$0B ; $BAA6 ; 10 +; .byte $0C,$0D,$B0,$B1,$0E,$0F,$10,$11 ; $BAAE ; 18 +; .byte $12,$13,$B8,$14,$15,$16,$17,$18 ; $BAB6 ; 20 +; .byte $19,$1A,$C0,$C1,$C2,$C3,$C4,$C5 ; $BABE ; 28 +; .byte $C6,$C7,$C8,$C9,$CA,$1B,$CC,$1C ; $BAC6 ; 30 +; .byte $1D,$1E,$D0,$D1,$D2,$1E,$D4,$D5 ; $BACE ; 38 +; .byte $20,$21,$D8,$22,$23,$24,$25,$26 ; $BAD6 ; 40 +; .byte $27,$28,$E0,$E1,$E2,$E3,$E4,$29 ; $BADE ; 48 +; .byte $2A,$2B,$E8,$2C,$2D,$2E,$2F,$30 ; $BAE6 ; 50 +; .byte $31,$32,$F0,$F1,$33,$34,$35,$36 ; $BAEE ; 58 +; .byte $37,$38,$F8,$39,$3A,$3B,$3C,$3D ; $BAF6 ; 60 +; .byte $3E,$3F,$13,$00,$01,$02,$01,$00 ; $BAFE ; 68 +; .byte $00,$00,$00,$00,$00,$00,$00,$00 +; .byte $00,$00,$00,$00,$00,$00,$00,$00 + + +;bit2tbl: .res 86 ; = nibtbl+128 +;filbuf: .res 4 ; = bit2tbl+86 + + + ;dataend = filbuf+4 + + .include "init_vars.s" + +loader_end: + +.assert ((>loader_end) - (>loader_start)) <16, error, "loader too big" diff --git a/tfv/text_print.s b/tfv/text_print.s new file mode 100644 index 00000000..dada5ca0 --- /dev/null +++ b/tfv/text_print.s @@ -0,0 +1,191 @@ + ;============================= + ; normal_text + ;============================= + ; modify so print normal text +normal_text: + + ; want ora #$80 + lda #$09 + sta ps_smc1 + + lda #$80 + sta ps_smc1+1 + + rts + + ;============================= + ; inverse_text + ;============================= + ; modify so print inverse text +inverse_text: + + ; want and #$3f + lda #$29 + sta ps_smc1 + + lda #$3f + sta ps_smc1+1 + + rts + + + ;============================= + ; raw text + ;============================= + ; modify so print raw string +raw_text: + + ; want nop nop + lda #$EA + sta ps_smc1 + + lda #$EA + sta ps_smc1+1 + + rts + + + + ;================================ + ; move_and_print + ;================================ + ; get X,Y from OUTL/OUTH + ; then print following string to that address + ; stop at NUL + ; convert to APPLE ASCII (or with 0x80) + ; leave OUTL/OUTH pointing to next string + +move_and_print: + ldy #0 + lda (OUTL),Y + sta CH + iny + lda (OUTL),Y + 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 + + clc + lda OUTL + adc #2 + sta OUTL + lda OUTH + adc #0 + sta OUTH + + ;================================ + ; print_string + ;================================ + +print_string: + ldy #0 +print_string_loop: + lda (OUTL),Y + beq done_print_string +ps_smc1: + and #$3f ; make sure we are inverse + sta (BASL),Y + iny + bne print_string_loop +done_print_string: + iny + clc + tya + adc OUTL + sta OUTL + lda OUTH + adc #0 + sta OUTH + + rts + + + ;================================ + ; move and print a list of lines + ;================================ +move_and_print_list: + jsr move_and_print + ldy #0 + lda (OUTL),Y + bpl move_and_print_list + + rts + + +.if 0 + ;================================ + ; move and print a list of lines + ;================================ +move_and_print_list_both_pages: + lda DRAW_PAGE + pha + + lda OUTL + pha + lda OUTH + pha + + lda #0 + sta DRAW_PAGE + + jsr move_and_print_list + + pla + sta OUTH + pla + sta OUTL + + lda #4 + sta DRAW_PAGE + + jsr move_and_print_list + + pla + sta DRAW_PAGE + + + rts + + + + ;======================= + ; print to both pages + ;======================= +print_both_pages: + lda DRAW_PAGE + pha + + lda OUTL + pha + lda OUTH + pha + + lda #0 + sta DRAW_PAGE + + jsr move_and_print + + pla + sta OUTH + pla + sta OUTL + + lda #4 + sta DRAW_PAGE + + jsr move_and_print + + pla + sta DRAW_PAGE + + + rts +.endif diff --git a/tfv/tfv.s b/tfv/tfv.s index 23754a5a..191a2fa5 100644 --- a/tfv/tfv.s +++ b/tfv/tfv.s @@ -1,4 +1,4 @@ -.include "tfv_zp.inc" +.include "zp.inc" .include "hardware.inc" ;================================ @@ -13,35 +13,6 @@ ; real hardware and AppleWin default ; to different values - ;=================================== - ; zero out the zero page that we use - ;=================================== - - ; memset() - - ;=================================== - ; Clear top/bottom of page 0 and 1 - ;=================================== - - jsr clear_screens - - ;========================== - ; Do Opening - ;========================== - - jsr opening - - ;====================== - ; show the title screen - ;====================== - - jsr title_screen - - ;====================== - ; get name - ;====================== - - jsr enter_name ;===================== ; Flying @@ -84,8 +55,8 @@ exit: ; External modules ;=============================================== -.include "tfv_opener.s" -.include "tfv_title.s" +;.include "tfv_opener.s" +;.include "tfv_title.s" .include "tfv_textentry.s" .include "tfv_flying.s" .include "tfv_worldmap.s" diff --git a/tfv/tfv_opener.s b/tfv/tfv_opener.s index 5133c22d..47734911 100644 --- a/tfv/tfv_opener.s +++ b/tfv/tfv_opener.s @@ -1,7 +1,10 @@ ;============================= ; show VMW splash screen ;============================= + opening: + jsr normal_text + lda #100 sta MATCH jsr draw_logo @@ -27,17 +30,11 @@ shine_loop: ; Done, print string - lda #8 - sta CH ; HTAB 9 - - lda #20 - sta CV ; VTAB 21 - - - lda #>(vmwsw_string) - sta OUTH lda #<(vmwsw_string) sta OUTL + lda #>(vmwsw_string) + sta OUTH + jsr move_and_print ; print("A VMW SOFTWARE PRODUCTION"); @@ -163,5 +160,5 @@ draw_logo: rts vmwsw_string: - .asciiz "A VMW SOFTWARE PRODUCTION" + .byte 8,20,"A VMW SOFTWARE PRODUCTION",0 diff --git a/tfv/tfv_title.s b/tfv/tfv_title.s index 884580dd..4d3f1f84 100644 --- a/tfv/tfv_title.s +++ b/tfv/tfv_title.s @@ -1,3 +1,42 @@ +; Display the TFV title screen +; +; this is the opener, title screen, new game creation, and load game code + +.include "zp.inc" +.include "hardware.inc" +.include "common_defines.inc" + + ;================================ + ; Clear screen and setup graphics + ;================================ + + jsr HOME + bit PAGE0 ; set page 0 + bit LORES ; Lo-res graphics + bit TEXTGR ; mixed gr/text mode + bit SET_GR ; set graphics + + lda #0 + sta DISP_PAGE + lda #4 + sta DRAW_PAGE + + ;=================================== + ; Clear top/bottom of page 0 and 1 + ;=================================== + + jsr clear_screens + + ;========================== + ; Do Opening + ;========================== + + jsr opening + + ;====================== + ; show the title screen + ;====================== + ; Title Screen title_screen: @@ -36,4 +75,45 @@ title_screen: jsr wait_until_keypressed + + + ;================================= + ; enter name + + ; jsr enter_name + + ;================================= + ; move on to flying + + lda #LOAD_FLYING + sta WHICH_LOAD + rts + + +;=============================================== +; External modules +;=============================================== + +.include "tfv_opener.s" + +.include "gr_pageflip.s" +.include "text_print.s" +.include "gr_fast_clear.s" +.include "gr_vlin.s" +.include "gr_copy.s" +.include "decompress_fast_v2.s" +.include "gr_offsets.s" +.include "wait_keypressed.s" + +;=============================================== +; Variables +;=============================================== + +enter_name_string: + .asciiz "PLEASE ENTER A NAME:" + +name: + .byte $0,$0,$0,$0,$0,$0,$0,$0 + +.include "graphics_title/tfv_title.inc" diff --git a/tfv/wait_keypressed.s b/tfv/wait_keypressed.s new file mode 100644 index 00000000..a2229677 --- /dev/null +++ b/tfv/wait_keypressed.s @@ -0,0 +1,6 @@ + +wait_until_keypressed: + lda KEYPRESS ; check if keypressed + bpl wait_until_keypressed ; if not, loop + bit KEYRESET + rts diff --git a/tfv/tfv_zp.inc b/tfv/zp.inc similarity index 55% rename from tfv/tfv_zp.inc rename to tfv/zp.inc index b01b6068..1ec9e209 100644 --- a/tfv/tfv_zp.inc +++ b/tfv/zp.inc @@ -22,37 +22,6 @@ INVFLG = $32 ; More zero-page addresses ; we try not to conflict with anything DOS, MONITOR or BASIC related -COLOR1 = $E0 -COLOR2 = $E1 -MATCH = $E2 -XX = $E3 -YY = $E4 -YADD = $E5 -LOOP = $E6 -MEMPTRL = $E7 -MEMPTRH = $E8 -NAMEL = $E9 -NAMEH = $EA -NAMEX = $EB -CHAR = $EC -DISP_PAGE = $ED -DRAW_PAGE = $EE - -FIRST = $F0 -LASTKEY = $F1 -PADDLE_STATUS = $F2 -XPOS = $F3 -YPOS = $F4 -TEMP = $FA -RUN = $FA -TEMP2 = $FB -TEMPY = $FB -INL = $FC -INH = $FD -OUTL = $FE -OUTH = $FF - - ;; Flying Routine Only TURNING = $60 @@ -96,9 +65,6 @@ LAST_SPACEY_I = $88 LAST_MAP_COLOR = $89 DRAW_SKY = $8A COLOR_MASK = $8B - -SHIPY = $E4 - ;; World Map Only ODD = $7B @@ -115,79 +81,68 @@ MAP_X = $85 GROUND_COLOR = $86 -.if 0 +LEVEL_OVER = $A0 +JOYSTICK_ENABLED= $A1 +FRAMEL = $A2 +FRAMEH = $A3 +WHICH_LOAD = $A4 -KEYPRESS = $C000 -KEYRESET = $C010 +COLOR1 = $E0 +COLOR2 = $E1 +MATCH = $E2 +XX = $E3 +YY = $E4 +SHIPY = $E4 +YADD = $E5 +LOOP = $E6 +MEMPTRL = $E7 +MEMPTRH = $E8 +NAMEL = $E9 +NAMEH = $EA +NAMEX = $EB +CHAR = $EC +DISP_PAGE = $ED +DRAW_PAGE = $EE -;; SOFT SWITCHES -SET_GR = $C050 -SET_TEXT = $C051 -FULLGR = $C052 -TEXTGR = $C053 -PAGE0 = $C054 -PAGE1 = $C055 -LORES = $C056 -HIRES = $C057 - -PADDLE_BUTTON0 = $C061 -PADDL0 = $C064 -PTRIG = $C070 - -;; BASIC ROUTINES - -NORMAL = $F273 - -;; MONITOR ROUTINES - -HLINE = $F819 ;; HLINE Y,$2C at A -VLINE = $F828 ;; VLINE A,$2D at Y -CLRSCR = $F832 ;; Clear low-res screen -CLRTOP = $F836 ;; clear only top of low-res screen -SETCOL = $F864 ;; COLOR=A -TEXT = $FB36 -TABV = $FB5B ;; VTAB to A -BASCALC = $FBC1 ;; -VTAB = $FC22 ;; VTAB to CV -HOME = $FC58 ;; Clear the text screen -WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us -SETINV = $FE80 ;; INVERSE -SETNORM = $FE84 ;; NORMAL -COUT = $FDED ;; output A to screen -COUT1 = $FDF0 ;; output A to screen +FIRST = $F0 +LASTKEY = $F1 +PADDLE_STATUS = $F2 +XPOS = $F3 +YPOS = $F4 +TEMP = $FA +RUN = $FA +TEMP2 = $FB +TEMPY = $FB +INL = $FC +INH = $FD +OUTL = $FE +OUTH = $FF -COLOR_BLACK = 0 -COLOR_RED = 1 -COLOR_DARKBLUE = 2 -COLOR_PURPLE = 3 -COLOR_DARKGREEN = 4 -COLOR_GREY = 5 -COLOR_MEDIUMBLUE = 6 -COLOR_LIGHTBLUE = 7 -COLOR_BROWN = 8 -COLOR_ORANGE = 9 -COLOR_GREY2 = 10 -COLOR_PINK = 11 -COLOR_LIGHTGREEN = 12 -COLOR_YELLOW = 13 -COLOR_AQUA = 14 -COLOR_WHITE = 15 +; read any file slot 6 version +; based on FASTLD6 and RTS copyright (c) Peter Ferrie 2011-2013,2018 -COLOR_BOTH_RED = $11 -COLOR_BOTH_DARKBLUE = $22 -COLOR_BOTH_DARKGREEN = $44 -COLOR_BOTH_GREY = $55 -COLOR_BOTH_MEDIUMBLUE = $66 -COLOR_BOTH_LIGHTBLUE = $77 -COLOR_BOTH_BROWN = $88 -COLOR_BOTH_ORANGE = $99 -COLOR_BOTH_LIGHTGREEN = $CC -COLOR_BOTH_YELLOW = $DD -COLOR_BOTH_WHITE = $FF +; modified to assemble with ca65 -- vmw +; added code to patch it to run from current disk slot -- vmw + + + adrlo = $26 ; constant from boot prom + adrhi = $27 ; constant from boot prom + tmpsec = $3c ; constant from boot prom + reqsec = $3d ; constant from boot prom + sizelo = $44 + sizehi = $45 + secsize = $46 + + ldsizel = $70 + ldsizeh = $71 + namlo = $7b + namhi = $7c + step = $7d ; state for stepper motor + tmptrk = $7e ; temporary copy of current track + phase = $7f ; current phase for /seek -.endif