[go: up one dir, main page]

Menu

[r97]: / psrp / asm / t1b.asm  Maximize  Restore  History

Download this file

119 lines (91 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
;
; Narrative number BCD creater
;
; Written in TASM 3.0.1
;
#include "vars.asm"
; in-line number display
; Old: inline looping (costs space), simple, direct output
; New: renders string to a temp buffer for wrapping,
; stores a flag to tell if it was singular or plural,
; pulls digit calculation out to save space
; 105 bytes
.org $33f6 ; $33f6-3493 ($96)
jr z,DRAW_NUMBER ; draw number if z
call $34f2 ; else draw a regular letter
jp $3365 ; and loop
DRAW_NUMBER:
push hl ; Save string ptr
push bc ; Width, temp
push ix ; Temp
ld hl,($c2c5) ; Load 16-bit parameter
ld ix,TEMP_STR ; Decode to buffer
ld bc,10000 ; # 10000's
call BCD_Digit
ld (ix+$00),A
ld bc,1000 ; # 1000's
call BCD_Digit
ld (ix+$01),A
ld bc,100 ; # 100's
call BCD_Digit
ld (ix+$02),A
ld bc,10 ; # 10's
call BCD_Digit
ld (ix+$03),A
ld a,l ; # 1's (BCD_Digit has made it only possible to be in the range 0..9)
add a,$01 ; add 1 because result = digit+1
ld (ix+$04),a
; scan the resultant string to see where the first non-zero digit is
; but we want to show the last digit even if it is zero
ld b,$04 ; look at 4 digits max
ld hl,TEMP_STR ; scan value
Scan:
ld a,(hl) ; load digit
cp $01 ; check for '0'
jr nz,Done
inc hl ; bump pointer
djnz Scan
Done:
ld a,b
inc a ; 1 <= length <= 5
ld (STR),hl ; save ptr to number string
ld (LEN),a ; save length
; ------------------------------------------------------------
; length != 1 -> must be plural
cp $01
jr nz,Plural ; length must be 1
; else check for '1'
ld a,(hl)
cp $02 ; last digit = '1'
jr nz,Plural
Singular:
xor a ; Clear flag
Plural:
; a is non-zero on jumps to this point
; and zero for the singular case
ld (SUFFIX),a ; 'x' mesata(s)
; ------------------------------------------------------------
pop ix ; Restore stack
pop bc
pop hl
inc hl ; Process next script
jp $3365
; ____________________________________________________________
BCD_Digit:
ld a,$00 ; Init digit value
; Note: $01 = '0', auto-bump
or a ; Clear carry flag
; subtract bc from hl until it overflows, then add it on again
; return a = number of subtractions done until overflow occurred,
; hl = hl % bc
; so a = hl / bc + 1 (integer division + 1)
; eg. hl = 9999, bc = 10000, a = 1
; eg. hl = 10000, bc = 10000, a = 2
BCD_Loop:
sbc hl,bc ; Divide by subtraction
inc a ; Bump place marker
jr nc,BCD_Loop ; No underflow
add hl,bc ; Restore value from underflowed subtraction
ret
.end ; TASM-only
; Replaces: