@@ -121,27 +121,27 @@ _AllocSprite:
121
121
; arg2 : pointer to malloc routine
122
122
; Returns:
123
123
; Pointer to allocated sprite, first byte width, second height
124
- ld iy , 0
125
- add iy , sp
126
- ld l , (iy + 3 ) ; l = width of sprite
127
- ld h , (iy + 6 ) ; h = height of sprite
128
- ld iy , (iy + 9 ) ; iy = pointer to some malloc
129
- push hl
130
- mlt hl ; width * height
131
- inc hl
132
- inc hl ; allocate space for width and height bytes
133
- push hl
134
- call __indcall ; call the malloc routine
135
- pop de
136
- pop de
137
- add hl , de
138
- or a , a
139
- sbc hl , de
140
- ret z ; check to make sure malloc did not fail
141
- ld (hl) , e ; store width
142
- inc hl
143
- ld (hl) , d ; store height
144
- dec hl ; return sprite pointer
124
+ ld bc , 3
125
+ push bc
126
+ pop hl
127
+ add hl , sp
128
+ ld e , (hl) ;; e = width
129
+ add hl , bc
130
+ ld d , (hl) ;; d = height
131
+ add hl , bc
132
+ ld hl , (hl) ;; hl = malloc
133
+ push de
134
+ mlt de ;; de = width * height
135
+ inc de ; +2 to store width and height
136
+ inc de ;; de = width * height + 2
137
+ push de
138
+ call _indcallHL_ASM ;; hl = malloc(width * height + 2)
139
+ pop de ;; de = width * height + 2
140
+ add hl , de ; this should never carry
141
+ sbc hl , de ; check if malloc failed (hl == 0)
142
+ pop de ;; e = width, d = height
143
+ ret z ; abort if malloc failed
144
+ ld (hl) , de ; store width and height
145
145
ret
146
146
147
147
;-------------------------------------------------------------------------------
@@ -4368,6 +4368,13 @@ _: rla
4368
4368
xor a , 1
4369
4369
ret
4370
4370
4371
+ ;-------------------------------------------------------------------------------
4372
+ _indcallHL_ASM:
4373
+ ; Calls HL
4374
+ ; Inputs:
4375
+ ; HL : Address to call
4376
+ jp (hl)
4377
+
4371
4378
;-------------------------------------------------------------------------------
4372
4379
CharSpacing_ASM:
4373
4380
. dl DefaultCharSpacing_ASM \.r
0 commit comments