diff options
-rw-r--r-- | mmss.s | 48 |
1 files changed, 31 insertions, 17 deletions
@@ -1,8 +1,19 @@ +;;; Subroutine: print_mmss +;;; Print the 3-byte jiffy count at cloksav as minute/seconds/centisec. +;;; +;;; Will print up to 10 characters using printchr. Normally it's only 8, +;;; because normally, the number of minutes is less than 100, even if +;;; the user unwisely enters a 5-digit particle count. +;;; +;;; Uses the floating point ROM routines, because it's easier to code +;;; this way (or so I thought!), and we don't need speed here. +;;; +;;; Caller must define cloksav (3 bytes), fptmp (6 bytes), and tmp1 +;;; (1 byte). These don't absolutely have to be in zero page, but +;;; it's nice if they are. +;;; print_mmss: -; calculate and print elapsed time -; uses the floating point ROM routines, because it's easier to code -; this way and we don't need speed here. ldx #0 ; low byte of 256 (0) stx FR0 inx @@ -30,16 +41,13 @@ print_mmss: jsr IFP ; ...ok, now: jsr FADD ; add the high bytes in jiffies, result in FR0 again - ; copy to fptmp before dividing (we need it later) + ; at this point, FR0 holds the 24-bit jiffy count, converted to FP. + ; copy to fptmp before dividing (we need it later). ldx #<fptmp ldy #>fptmp jsr FST0R - ; we now have the 3-byte jiffy count in FR0 and fptmp. ; 3600 NTSC jiffies or 3000 PAL jiffies = 1 minute, so divide. - ; floating point constants: - ; 3600.0 is $41,$36,$00,$00,$00,$00 - ; 3000.0 is $41,$30,$00,$00,$00,$00 jsr load_jpm_fr1 jsr FDIV ; FR0 = FR0 / FR1 (and FR1 is now garbage) @@ -64,6 +72,7 @@ truncloop: truncdone: ; print digits in FR0 + ; don't use FASC, easier to do it this way. lda FR0 and #$03 sta tmp1 @@ -81,6 +90,8 @@ floopdone: lda #':' jsr printchr + ; we don't have a modulus or remainder operation in the ROM, so + ; handroll one here. ; multiplication and division trash FR1, which is annoying. jsr load_jpm_fr1 jsr FMUL @@ -95,7 +106,7 @@ floopdone: jsr FSUB ; load 0.6 into FR1 so we can divide by it. - ; result will be number of centisec. + ; result will be number of centisec (e.g. 1050 for 10.5 sec). jsr zero_fr1 lda #$3f sta FR1 @@ -110,6 +121,7 @@ floopdone: ; FR0 has division result, which is centiseconds. ; if the exponent is 0, we're OK. otherwise, shift down ; one byte so we print 00 for the seconds. + ; again, avoid FASC. lda FR0 and #$0f bne twodigits @@ -123,18 +135,19 @@ twodigits: lda #'.' jsr printchr lda FR0+2 - jsr printhex - - rts + jmp printhex ; load jiffies-per-minute into FR1. needs done twice so ; it's a subroutine. +; floating point constants: +; 3600.0 is $41,$36,$00,$00,$00,$00 +; 3000.0 is $41,$30,$00,$00,$00,$00 load_jpm_fr1: jsr zero_fr1 lda #$41 ; excess-64 base-100 exponent and sign (bit 7 = 0 means positive) sta FR1 ldx #$36 ; 1st mantissa BCD byte, NTSC - lda PAL + lda PAL ; ask the GTIA what TV standard we're using and #$0e bne ntsc ldx #$30 ; 1st mantissa BCD byte, PAL @@ -142,9 +155,10 @@ ntsc: stx FR1+1 rts -; ZF1 does *not* just clear out FR0, it uses the X reg as an 8-bit -; pointer (to zero page only). +;;; Subroutine: zero_fr1. Zeroes out all 6 bytes of FR1. Counterpart +;;; to the OS's ZFR0. +;;; Note: ZF1 does *not* just clear out FR1, it uses the X reg as an 8-bit +;;; pointer (to zero page only). zero_fr1: ldx #FR1 - jsr ZF1 - rts + jmp ZF1 |