basic: convert_tgreene: add help message

This commit is contained in:
Vince Weaver 2022-05-31 13:47:25 -04:00
parent 105148be9d
commit 5b059ab037
4 changed files with 62 additions and 40 deletions

View File

@ -1,16 +1,34 @@
/* code by qkumba */ /* Based on code by qkumba */
/* TGreene improved the algorithm to be a bit smaller */
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h>
/* ASCII offset */
#define OFFSET 35 #define OFFSET 35
#define OFFSET2 35 #define OFFSET2 35
//#define OFFSET 35 /* We are jumping into the decoded code using the & operator */
/* This just does a jmp to $3F5 */
/* Easiest is to just load our code there */
/* The problem is this loads most of the code to the 1st text/lo-res page */
/* For text/lo-res programs instead load code so it ends at $3F8, */
/* usually you have a 3-byte jmp to the start of your code at $3F5 */
#define END_AT_3F5 0 #define END_AT_3F5 0
#define BEGIN_AT_3F5 1 #define BEGIN_AT_3F5 1
static int print_help(char *name) {
printf("\n");
printf("Usage: %s [-e] [-h]\n",name);
printf("\t-e : ends program at 3F5 (useful for lo-res programs)\n");
printf("\t default is to start program at 3F5\n");
printf("\n");
return 0;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -28,6 +46,10 @@ int main(int argc, char **argv) {
if (argv[1][1]=='e') { if (argv[1][1]=='e') {
mode=END_AT_3F5; mode=END_AT_3F5;
} }
if (argv[1][1]=='h') {
print_help(argv[0]);
exit(1);
}
} }
} }

View File

@ -12,11 +12,12 @@ all: star.dsk
$(DOS33): $(DOS33):
cd ../../../utils/dos33fs-utils && make cd ../../../utils/dos33fs-utils && make
star.dsk: $(DOS33) HELLO STAR STARS star.dsk: $(DOS33) HELLO STAR STARS STARS_BOT
cp $(EMPTY_DISK)/empty.dsk star.dsk cp $(EMPTY_DISK)/empty.dsk star.dsk
$(DOS33) -y star.dsk SAVE A HELLO $(DOS33) -y star.dsk SAVE A HELLO
$(DOS33) -y star.dsk BSAVE -a 0xc00 STAR $(DOS33) -y star.dsk BSAVE -a 0xc00 STAR
$(DOS33) -y star.dsk BSAVE -a 0xc00 STARS $(DOS33) -y star.dsk BSAVE -a 0xc00 STARS
$(DOS33) -y star.dsk BSAVE -a 0xc00 STARS_BOT
### ###
@ -42,14 +43,14 @@ stars.o: stars.s
### ###
STAR_BOT: star_bot.o STARS_BOT: stars_bot.o
ld65 -o STAR_BOT star_bot.o -C $(LINKERSCRIPTS)/apple2_36b.inc ld65 -o STARS_BOT stars_bot.o -C $(LINKERSCRIPTS)/apple2_c00.inc
star_bot.o: star_bot.s stars_bot.o: stars_bot.s
ca65 -o star_bot.o star_bot.s -l star_bot.lst ca65 -o stars_bot.o stars_bot.s -l stars_bot.lst
### ###
clean: clean:
rm -f *~ *.o *.lst HELLO STAR STAR_BOT rm -f *~ *.o *.lst HELLO STAR STARS STARS_BOT

View File

@ -8,6 +8,7 @@
; 140 bytes -- 0 is already in X ; 140 bytes -- 0 is already in X
; 143 bytes -- stars move independently ; 143 bytes -- stars move independently
; 140 bytes -- optimize XPOS in multiple calls to draw_stars ; 140 bytes -- optimize XPOS in multiple calls to draw_stars
; 145 bytes -- color changing background
SPEAKER = $C030 SPEAKER = $C030
SET_GR = $C050 SET_GR = $C050
@ -33,7 +34,7 @@ XPOS = $77
FRAME = $6D FRAME = $6D
PAGE = $6E PAGE = $6E
LINE = $6F
;.zeropage ;.zeropage
;.globalzp pattern_smc ;.globalzp pattern_smc
@ -62,7 +63,11 @@ main_loop:
jsr WAIT jsr WAIT
inc FRAME ; increment frame # inc FRAME ; increment frame #
bne no_cs
inc bg_smc+1
no_cs:
;================================= ;=================================
; clear lo-res screen, page1/page2 ; clear lo-res screen, page1/page2
;================================= ;=================================
@ -71,6 +76,7 @@ main_loop:
ldx #4 ; lores is 1k, so 4 pages ldx #4 ; lores is 1k, so 4 pages
full_loop: full_loop:
ldy #$00 ; clear whole page ldy #$00 ; clear whole page
bg_smc:
lda #$55 ; color lda #$55 ; color
inner_loop: inner_loop:
sta (OUTL),Y sta (OUTL),Y

View File

@ -13,6 +13,8 @@
; 143 bytes -- speed up the color transition ; 143 bytes -- speed up the color transition
; 144 bytes -- tried to share adjust_page in subroutine, backfired ; 144 bytes -- tried to share adjust_page in subroutine, backfired
; 143 bytes -- revert last change ; 143 bytes -- revert last change
; 142 bytes -- draw stars right to left
; 141 bytes -- assume GBASCALC always leaves C set to 0
SPEAKER = $C030 SPEAKER = $C030
SET_GR = $C050 SET_GR = $C050
@ -24,7 +26,7 @@ LORES = $C056 ; Enable LORES graphics
HGR2 = $F3D8 HGR2 = $F3D8
PLOT = $F800 ; PLOT AT Y,A (A colors output, Y preserved) PLOT = $F800 ; PLOT AT Y,A (A colors output, Y preserved)
GBASCALC = $F847 ; Y in A, put addr in GBASL/GBASH GBASCALC = $F847 ; Y in A, put addr in GBASL/GBASH (what is C?)
SETGR = $FB40 SETGR = $FB40
WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us
@ -33,6 +35,7 @@ GBASH = $27
YPOS = $76 YPOS = $76
XPOS = $77 XPOS = $77
PO = $78
FRAME = $6D FRAME = $6D
PAGE = $6E PAGE = $6E
@ -55,7 +58,7 @@ main_loop:
asl ; make OUTH $4 or $8 depending on value in PAGE asl ; make OUTH $4 or $8 depending on value in PAGE
; which we have in A above or at end of loop ; which we have in A above or at end of loop
asl ; C is 0 asl ; (this also sets C to 0)
adc #4 adc #4
sta GBASH sta GBASH
@ -63,11 +66,11 @@ main_loop:
inc FRAME ; increment frame # inc FRAME ; increment frame #
lda FRAME lda FRAME
and #$1f ; cycle colors ever 32 frames and #$1f ; cycle colors ever 32 frames
bne no_cs bne no_color_cycle
inc bg_smc+1 inc bg_smc+1
no_cs: no_color_cycle:
lda #100 ; pause a bit lda #100 ; pause a bit
jsr WAIT jsr WAIT
@ -79,10 +82,10 @@ no_cs:
; clear lo-res screen, page1/page2 ; clear lo-res screen, page1/page2
;================================= ;=================================
; proper with avoiding screen holes is ~25 instructions ; proper with avoiding screen holes is ~25 instructions
; this is more like 16
; assume GBASL/GBASH already points to proper $400 or $800
ldx #4 ; lores is 1k, so 4 pages ldx #4 ; lores is 1k, so 4 pages
; stx GBASH
; jsr adjust_page
full_loop: full_loop:
ldy #$00 ; clear whole page ldy #$00 ; clear whole page
bg_smc: bg_smc:
@ -96,12 +99,15 @@ inner_loop:
dex dex
bne full_loop bne full_loop
; X=0
; Y=0
; A=color
;==================== ;====================
; draw the stars ; draw the stars
;==================== ;====================
txa ; X is zero here lda #32 ; start from right to save a byte
;====================== ;======================
; draw 8x8 bitmap star ; draw 8x8 bitmap star
@ -112,7 +118,6 @@ draw_star:
; calculate YPOS ; calculate YPOS
sta XPOS sta XPOS
; lda XPOS
lsr ; make middle star offset+4 from others lsr ; make middle star offset+4 from others
lsr lsr
@ -130,17 +135,15 @@ boxloop:
adc YPOS adc YPOS
jsr GBASCALC ; calc address of line in X (Y-coord) jsr GBASCALC ; calc address of line in X (Y-coord)
; GBASL is in A at this point ; GBASL is in A at this point
; is C always 0?
clc ; clc
adc XPOS ; adjust to X-coord adc XPOS ; adjust to X-coord
sta GBASL sta GBASL
; adjust for proper page ; adjust for proper page
; jsr adjust_page
lda PAGE ; want to add 0 or 4 (not 0 or 1) lda PAGE ; want to add 0 or 4 (not 0 or 1)
asl asl
asl ; this sets C to 0 asl ; this sets C to 0
@ -172,23 +175,22 @@ its_transparent:
dex dex
bpl boxloop bpl boxloop
lda XPOS lda XPOS ; move to next position
clc ; going right to left saves 2 bytes for cmp
adc #16 sec
sbc #16
cmp #48 bpl draw_star
bne draw_star
; X is $FF here ; X is $FF here
; Y is $FF here ; Y is $FF here
; A is 48 here ; A is -16 here
;====================== ;======================
; flip page ; flip page
;====================== ;======================
lda PAGE lda PAGE ; 0 or 1
tax tax
ldy PAGE1,X ; flip page ldy PAGE1,X ; flip page
@ -198,19 +200,10 @@ its_transparent:
bpl main_loop ; bra bpl main_loop ; bra
; GBASL in A
;adjust_page:
; sta GBASL
; lda PAGE ; want to add 0 or 4 (not 0 or 1)
; asl
; asl ; this sets C to 0
; adc GBASH
; sta GBASH
; rts
;=================
; star bitmap ; star bitmap
;=================
;012|456| ;012|456|
; @ ; ; @ ;