From a8970f761b4a16c5f675000f203d9f12804fe36b Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sat, 6 May 2017 19:29:19 -0400 Subject: [PATCH] tfv: have RLE image loading working forgot how much I hate 6502 assembler --- gr-sim/gr-sim.c | 77 +++++++++++++------- gr-sim/tfv.c | 3 +- tfv/Makefile | 9 ++- tfv/tfv.s | 187 ++++++++++++++++++++++++++++++++++++++++++++++++ tfv/title.inc | 38 ++++++++++ 5 files changed, 286 insertions(+), 28 deletions(-) create mode 100644 tfv/tfv.s create mode 100644 tfv/title.inc diff --git a/gr-sim/gr-sim.c b/gr-sim/gr-sim.c index 4d6452e5..a7a54aac 100644 --- a/gr-sim/gr-sim.c +++ b/gr-sim/gr-sim.c @@ -44,6 +44,8 @@ unsigned char a,y,x; #define COLOR 0x30 #define FIRST 0xF0 +#define TEMP 0xFA + static SDL_Surface *sdl_screen=NULL; int grsim_input(void) { @@ -487,45 +489,68 @@ int home(void) { int grsim_unrle(unsigned char *rle_data, int address) { - int i,total=0; // int xoffset=0; // int yoffset=0; - int xsize,ysize,end,run,value; - unsigned char *out_pointer; - int offset,x=0,y=0; + unsigned char s; +// int out_pointer; - xsize=rle_data[0]; - ysize=rle_data[1]; + ram[GBASL]=0; // input address + ram[GBASH]=0; - end=xsize*(ysize/2); - out_pointer=ram+address; - offset=2; + x=0; + y=0; + + ram[BASL]=address&0xff; + ram[BASH]=address>>8; + + ram[CV]=0; + ram[CH]=rle_data[y_indirect(GBASL,y)]; + y++; +// ysize=rle_data[1]; + y++; while(1) { - run=rle_data[offset]; - offset++; - value=rle_data[offset]; - offset++; + a=rle_data[y_indirect(GBASL,y)]; + if (a==0xff) break; + ram[TEMP]=a; - for(i=0;i=40) { - out_pointer+=0x58; - y+=2; - if (y>14) { - y=0; - out_pointer-=(0x400-0x28); -// printf("%d %x\n",y,address+(y/2)*0x80); + if (x>=ram[CH]) { + if (ram[BASL]>0xa7) ram[BASH]++; + ram[BASL]+=0x58; + ram[CV]+=2; + if (ram[CV]>14) { + ram[CV]=0; + if (ram[BASL]<0xd8) { + ram[BASL]=ram[BASL]-0xd8; + ram[BASH]=ram[BASH]-0x4; + } + else { + ram[BASL]=ram[BASL]-0xd8; + ram[BASH]=ram[BASH]-0x3; + } } x=0; } + ram[TEMP]--; + if (ram[TEMP]==0) break; } - - if (total>=end) break; + y=s; } return 0; diff --git a/gr-sim/tfv.c b/gr-sim/tfv.c index b91d04e0..55b9c94f 100644 --- a/gr-sim/tfv.c +++ b/gr-sim/tfv.c @@ -26,7 +26,8 @@ static unsigned char title_rle[]= 0x0C,0x00,0x02,0xCC,0x01,0x44,0x01,0x55,0x09,0x00,0x01,0x0D,0x01,0x00,0x01,0xBB,0x03,0xB1,0x01,0xBB,0x01,0x00,0x01,0x0D,0x04,0x00,0x02,0xBB, 0x0C,0x00,0x01,0x0C,0x01,0x4C,0x01,0x44,0x01,0x55,0x0C,0x00,0x02,0xBB,0x06,0x00,0x01,0x20,0x01,0x22,0x01,0x2B,0x01,0x0B, 0x0E,0x00, 0x02,0x05, 0x09,0x00, 0x01,0x20, 0x06,0x22, 0x03,0x20, - 0x02,0x22, 0x01,0x02, 0x0a,0x0, + 0x02,0x22, 0x01,0x02, 0x09,0x00, + 0xff,0xff // " 55 2222222222222" }; diff --git a/tfv/Makefile b/tfv/Makefile index d9ca7174..e68266d5 100644 --- a/tfv/Makefile +++ b/tfv/Makefile @@ -5,10 +5,17 @@ PNG2GR = ../gr-utils/png2gr all: tfv.dsk -tfv.dsk: TITLE.GR ED +tfv.dsk: TITLE.GR TFV ED + $(DOS33) -y tfv.dsk BSAVE -a 0xc00 TFV $(DOS33) -y tfv.dsk BSAVE -a 0x400 TITLE.GR $(DOS33) -y tfv.dsk BSAVE -a 0x900 ED +TFV: tfv.o + ld65 -o TFV tfv.o -C ./apple2_c00.inc + +tfv.o: tfv.s title.inc + ca65 -o tfv.o tfv.s -l tfv.lst + ED: duet.o ld65 -o ED duet.o -C ./apple2_900.inc diff --git a/tfv/tfv.s b/tfv/tfv.s new file mode 100644 index 00000000..98fd85f5 --- /dev/null +++ b/tfv/tfv.s @@ -0,0 +1,187 @@ +.define EQU = + +;; SOFT SWITCHES +GR EQU $C050 +TEXT EQU $C051 +FULLGR EQU $C052 +TEXTGR EQU $C053 +PAGE0 EQU $C054 +PAGE1 EQU $C055 +LORES EQU $C056 +HIRES EQU $C057 + +;; MONITOR ROUTINES +HLINE EQU $F819 ;; HLINE Y,$2C at A +VLINE EQU $F828 ;; VLINE A,$2D at Y +CLRSCR EQU $F832 ;; Clear low-res screen +CLRTOP EQU $F836 ;; clear only top of low-res screen +SETCOL EQU $F864 ;; COLOR=A +BASCALC EQU $FBC1 ;; +HOME EQU $FC58 ;; Clear the text screen +WAIT EQU $FCA8 ;; delay 1/2(26+27A+5A^2) us +SETINV EQU $FE80 ;; INVERSE +SETNORM EQU $FE84 ;; NORMAL +COUT1 EQU $FDF0 ;; output A to screen + +;; Zero page addresses +WNDLFT EQU $20 +WNDWDTH EQU $21 +WNDTOP EQU $22 +WNDBTM EQU $23 +CH EQU $24 +CV EQU $25 +GBASL EQU $26 +GBASH EQU $27 +BASL EQU $28 +BASH EQU $29 +H2 EQU $2C +V2 EQU $2D +MASK EQU $2E +COLOR EQU $30 +FIRST EQU $F0 + +TEMP EQU $FA +RUN EQU $FA +TEMP2 EQU $FB + + ;============================= + ; set low-res graphics, page 0 + ;============================= + jsr HOME + jsr set_gr_page0 + + ;================= + ; clear the screen + ;================= + jsr CLRTOP + + + lda #>(title_image) + sta GBASH + lda #<(title_image) + sta GBASL + jsr load_rle_gr + + lda #$4 + sta BASH + lda #$0 + sta BASL ; 0x400 is GR page 0 + + ; Return to BASIC? + rts + + ;================= + ; load RLE image + ;================= + ; Output is BASH/BASL + ; Input is in GBASH/GBASL +load_rle_gr: + lda #$0 + tax + tay ; init X and Y to 0 + + sta CV ; ycoord=0 + + lda (GBASL),y ; load xsize + sta CH + iny ; (we should check if we had + ; bad luck and overflows page) + +rle_loop: + lda (GBASL),y ; load run value + cmp #$ff ; if 0xff + beq rle_done ; we are done + sta RUN + iny ; point to next value + bne rle_yskip1 ; if overflow, increment address + inc GBASH +rle_yskip1: + lda (GBASL),y ; load value to write + iny + bne rle_yskip2 + inc GBASH +rle_yskip2: + sty TEMP2 ; save y for later + pha + lda #$0 + tay + pla ; convoluted way to set y to 0 + +rle_run_loop: + sta (BASL),y + inc BASL + bne rle_skip3 + inc BASH ; write out value +rle_skip3: + inx + cpx CH + bcc rle_not_eol ; branch if less than + + pha + + lda BASL + cmp #$a7 + bcc rle_add_skip + inc BASH +rle_add_skip: + clc + adc #$58 + sta BASL + inc CV + inc CV + lda CV + cmp #15 + bcc rle_no_wrap + + lda #$0 + sta CV + sec ; set carry for borrow purpose + lda BASL + sbc #$d8 ; perform subtraction on the LSBs + sta BASL + lda BASH ; do the same for the MSBs, with carry + sbc #$3 ; set according to the previous result + sta BASH + +rle_no_wrap: + lda #$0 + tax + pla + +rle_not_eol: + dec RUN + bne rle_run_loop + + ldy TEMP2 + sec + bcs rle_loop + +rle_done: + lda #$15 + sta CV + rts + + + ;========================================================== + ; set_text_page0 + ;========================================================== + ; +set_text_page0: + bit PAGE0 ; set page0 + bit TEXT ; set text mode + rts + + ;========================================================== + ; set_gr_page0 + ;========================================================== + ; +set_gr_page0: + ;lda #4 + ;sta GR_PAGE + bit PAGE0 ; set page 0 + bit LORES ; Lo-res graphics + bit TEXTGR ; mixed gr/text mode + bit GR ; set graphics + rts + +.include "title.inc" diff --git a/tfv/title.inc b/tfv/title.inc new file mode 100644 index 00000000..119a1b12 --- /dev/null +++ b/tfv/title.inc @@ -0,0 +1,38 @@ +title_image: + .byte $28 + .byte $01,$00,$19,$20 + .byte $0F,$00,$01,$22,$03,$66,$01,$22,$01,$62 + .byte $01,$66,$01,$62,$01,$22,$01,$66,$03,$22 + .byte $01,$66,$01,$26,$01,$62,$01,$22,$01,$62 + .byte $01,$26,$01,$62,$01,$22,$03,$66,$01,$22 + .byte $01,$55,$01,$00,$03,$11,$01,$44,$03,$22 + .byte $01,$44,$03,$22 + .byte $02,$00,$02,$22,$01,$66,$02,$22,$01,$66 + .byte $01,$62,$01,$66,$01,$22,$01,$66,$03,$22 + .byte $01,$66,$01,$26,$01,$62,$01,$22,$01,$66 + .byte $01,$22,$01,$66,$02,$22,$01,$66,$02,$22 + .byte $01,$55,$01,$00,$01,$01,$01,$11,$01,$41 + .byte $01,$44,$01,$42,$01,$22,$01,$42,$01,$44 + .byte $01,$42,$01,$22,$01,$02 + .byte $02,$00,$02,$22,$01,$66,$02,$22,$01,$66,$01,$22,$01,$66,$01,$22,$03,$66,$01,$22,$01,$66,$01,$62,$01,$26,$01,$22,$01,$26,$01,$62,$01,$26,$02,$22,$01,$66,$02,$22,$01,$55,$02,$00,$01,$11,$03,$44,$01,$22,$03,$44,$01,$22 + .byte $03,$00,$01,$02,$18,$52,$01,$55 + .byte $0E,$00,$1E,$60 + .byte $0A,$00,$01,$66,$03,$22,$01,$66,$01,$26,$01,$22,$01,$26,$01,$66,$01,$22,$01,$26,$01,$66,$01,$22,$01,$66,$03,$22,$01,$66,$01,$26,$01,$22,$01,$26,$01,$66,$01,$26,$02,$62,$01,$66,$01,$22,$01,$66,$01,$22,$01,$66,$01,$55 + .byte $09,$00,$01,$66,$01,$22,$01,$26,$02,$66,$01,$22,$01,$26,$01,$22,$01,$66,$01,$22,$01,$62,$01,$26,$01,$22,$02,$66,$01,$22,$02,$66,$01,$22,$01,$26,$01,$22,$01,$66,$01,$22,$02,$26,$01,$66,$01,$62,$01,$26,$01,$62,$01,$66,$01,$55 + .byte $09,$00,$01,$66,$01,$22,$03,$66,$01,$22,$01,$66,$01,$22,$01,$66,$01,$22,$01,$66,$01,$62,$01,$22,$02,$66,$01,$22,$02,$66,$01,$22,$01,$66,$01,$22,$01,$66,$02,$26,$01,$22,$02,$66,$01,$22,$02,$66,$01,$55 + .byte $09,$00,$01,$06,$1D,$56,$01,$55,$03,$00,$01,$10 + .byte $24,$00,$01,$10,$01,$00,$01,$10,$01,$11,$01,$01 + .byte $05,$00,$08,$CC,$01,$40,$09,$00,$01,$D0,$01,$0D,$01,$00,$01,$D0,$01,$0D,$01,$00,$01,$D0,$05,$00,$01,$11 + .byte $0A,$00,$01,$04,$04,$54,$02,$CC,$01,$44,$01,$55,$06,$00,$01,$D0,$01,$DD,$02,$D0,$01,$DD,$02,$D0,$01,$DD,$01,$D0,$03,$00,$02,$01,$01,$11,$02,$01 + .byte $0C,$00,$02,$CC,$01,$44,$01,$54,$01,$55,$06,$00,$01,$DD,$07,$BB,$01,$DD,$04,$00,$01,$10,$01,$11,$01,$10 + .byte $0C,$00,$02,$CC,$01,$44,$01,$54,$01,$55,$07,$00,$01,$DD,$01,$BB,$01,$BF,$01,$B0,$01,$BB,$01,$BF,$01,$B0,$01,$BB,$01,$DD,$03,$00,$01,$10,$03,$11,$01,$10 + .byte $0A,$00,$02,$CC,$01,$44,$01,$54,$01,$55,$08,$00,$01,$DD,$01,$DB,$01,$BB,$01,$3B,$01,$33,$02,$BB,$01,$DB,$01,$DD,$03,$00,$02,$01,$01,$11,$02,$01 + .byte $0A,$00,$02,$CC,$01,$44,$01,$55,$09,$00,$02,$DD,$05,$BB,$02,$DD,$05,$00,$01,$11 + .byte $0C,$00,$02,$CC,$01,$44,$01,$55,$09,$00,$01,$0D,$01,$00,$01,$BB,$03,$B1,$01,$BB,$01,$00,$01,$0D,$04,$00,$02,$BB + + .byte $0C,$00,$01,$0C,$01,$4C,$01,$44,$01,$55,$0C,$00,$02,$BB,$06,$00,$01,$20,$01,$22,$01,$2B,$01,$0B + + .byte $0E,$00,$02,$05,$09,$00,$01,$20,$06,$22,$03,$20 + .byte $02,$22,$01,$02,$09,$00 + .byte $ff,$ff +