Skip to content

Commit 2b83d5d

Browse files
committed
Shift screen to match that of Sinclair BASIC
Also adds test
1 parent 3e3ae7f commit 2b83d5d

File tree

6 files changed

+472
-1718
lines changed

6 files changed

+472
-1718
lines changed

library/sinclair.bas

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ REM This library includes other classic Sinclair ZX Spectrum Routines
2424
REM This is not the original Sinclair INPUT, but better than nothing
2525
#include once <input.bas>
2626

27-
REM This is to initialize USR "a" to a memory heap space
27+
REM This needed to initialize USR "a" to a memory heap space
2828
#include once <alloc.bas>
2929

3030
REM Now updates UDG system var to new UDG memory zone
3131
POKE Uinteger 23675, allocate(21 * 8) : REM 8 bytes per UDG (21 total)
3232

33+
REM Shift the screen 16 pixels UP to match that of the original BASIC
34+
REM ... unless the user has specified otherwise
35+
#ifndef SCREEN_Y_OFFSET
36+
# define SCREEN_Y_OFFSET 16
37+
#endif
38+
3339
#endif
3440

tests/functional/circle.asm

Lines changed: 155 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ PLOT:
291291
ex (sp), hl ; Callee
292292
ld b, a
293293
ld c, h
294+
#line 35 "/zxbasic/library-asm/plot.asm"
295+
#line 41 "/zxbasic/library-asm/plot.asm"
294296
ld a, 191
295297
cp b
296298
jr c, __PLOT_ERR ; jr is faster here (#1)
@@ -333,174 +335,169 @@ __PLOT_ERR:
333335
#line 6 "circle.asm"
334336
; Draws a circle at X, Y of radius R
335337
; X, Y on the Stack, R in accumulator (Byte)
336-
PROC
337-
LOCAL __CIRCLE_ERROR
338-
LOCAL __CIRCLE_LOOP
339-
LOCAL __CIRCLE_NEXT
338+
PROC
339+
LOCAL __CIRCLE_ERROR
340+
LOCAL __CIRCLE_LOOP
341+
LOCAL __CIRCLE_NEXT
340342
__CIRCLE_ERROR:
341343
jp __OUT_OF_SCREEN_ERR
342-
;; __CIRCLE_ERROR EQU __OUT_OF_SCREEN_ERR
343-
;; __CIRCLE_ERROR:
344-
;; ; Jumps here if out of screen
345-
;; scf ; Always sets carry Flag
346-
;;
347-
;; ld a, ERROR_OutOfScreen
348-
;; ld (ERR_NR), a
349-
;; ret
350344
CIRCLE:
351345
;; Entry point
352-
pop hl ; Return Address
353-
pop de ; D = Y
354-
ex (sp), hl ; __CALLEE__ convention
355-
ld e, h ; E = X
356-
ld h, a ; H = R
357-
add a, d
358-
sub 192
359-
jr nc, __CIRCLE_ERROR
360-
ld a, d
361-
sub h
362-
jr c, __CIRCLE_ERROR
363-
ld a, e
364-
sub h
365-
jr c, __CIRCLE_ERROR
366-
ld a, h
367-
add a, e
368-
jr c, __CIRCLE_ERROR
346+
pop hl ; Return Address
347+
pop de ; D = Y
348+
ex (sp), hl ; __CALLEE__ convention
349+
ld e, h ; E = X
350+
ld h, a ; H = R
351+
#line 31 "/zxbasic/library-asm/circle.asm"
352+
#line 37 "/zxbasic/library-asm/circle.asm"
353+
ld a, h
354+
add a, d
355+
sub 192
356+
jr nc, __CIRCLE_ERROR
357+
ld a, d
358+
sub h
359+
jr c, __CIRCLE_ERROR
360+
ld a, e
361+
sub h
362+
jr c, __CIRCLE_ERROR
363+
ld a, h
364+
add a, e
365+
jr c, __CIRCLE_ERROR
369366
; __FASTCALL__ Entry: D, E = Y, X point of the center
370367
; A = Radious
371368
__CIRCLE:
372-
push de
373-
ld a, h
374-
exx
375-
pop de ; D'E' = x0, y0
376-
ld h, a ; H' = r
377-
ld c, e
378-
ld a, h
379-
add a, d
380-
ld b, a
381-
call __CIRCLE_PLOT ; PLOT (x0, y0 + r)
382-
ld b, d
383-
ld a, h
384-
add a, e
385-
ld c, a
386-
call __CIRCLE_PLOT ; PLOT (x0 + r, y0)
387-
ld c, e
388-
ld a, d
389-
sub h
390-
ld b, a
391-
call __CIRCLE_PLOT ; PLOT (x0, y0 - r)
392-
ld b, d
393-
ld a, e
394-
sub h
395-
ld c, a
396-
call __CIRCLE_PLOT ; PLOT (x0 - r, y0)
397-
exx
398-
ld b, 0 ; B = x = 0
399-
ld c, h ; C = y = Radius
400-
ld hl, 1
401-
or a
402-
sbc hl, bc ; HL = f = 1 - radius
403-
ex de, hl
404-
ld hl, 0
405-
or a
406-
sbc hl, bc ; HL = -radius
407-
add hl, hl ; HL = -2 * radius
408-
ex de, hl ; DE = -2 * radius = ddF_y, HL = f
409-
xor a ; A = ddF_x = 0
410-
ex af, af' ; Saves it
369+
push de
370+
ld a, h
371+
exx
372+
pop de ; D'E' = x0, y0
373+
ld h, a ; H' = r
374+
ld c, e
375+
ld a, h
376+
add a, d
377+
ld b, a
378+
call __CIRCLE_PLOT ; PLOT (x0, y0 + r)
379+
ld b, d
380+
ld a, h
381+
add a, e
382+
ld c, a
383+
call __CIRCLE_PLOT ; PLOT (x0 + r, y0)
384+
ld c, e
385+
ld a, d
386+
sub h
387+
ld b, a
388+
call __CIRCLE_PLOT ; PLOT (x0, y0 - r)
389+
ld b, d
390+
ld a, e
391+
sub h
392+
ld c, a
393+
call __CIRCLE_PLOT ; PLOT (x0 - r, y0)
394+
exx
395+
ld b, 0 ; B = x = 0
396+
ld c, h ; C = y = Radius
397+
ld hl, 1
398+
or a
399+
sbc hl, bc ; HL = f = 1 - radius
400+
ex de, hl
401+
ld hl, 0
402+
or a
403+
sbc hl, bc ; HL = -radius
404+
add hl, hl ; HL = -2 * radius
405+
ex de, hl ; DE = -2 * radius = ddF_y, HL = f
406+
xor a ; A = ddF_x = 0
407+
ex af, af' ; Saves it
411408
__CIRCLE_LOOP:
412-
ld a, b
413-
cp c
414-
ret nc ; Returns when x >= y
415-
bit 7, h ; HL >= 0? : if (f >= 0)...
416-
jp nz, __CIRCLE_NEXT
417-
dec c ; y--
418-
inc de
419-
inc de ; ddF_y += 2
420-
add hl, de ; f += ddF_y
409+
ld a, b
410+
cp c
411+
ret nc ; Returns when x >= y
412+
bit 7, h ; HL >= 0? : if (f >= 0)...
413+
jp nz, __CIRCLE_NEXT
414+
dec c ; y--
415+
inc de
416+
inc de ; ddF_y += 2
417+
add hl, de ; f += ddF_y
421418
__CIRCLE_NEXT:
422-
inc b ; x++
423-
ex af, af'
424-
add a, 2 ; 1 Cycle faster than inc a, inc a
425-
inc hl ; f++
426-
push af
427-
add a, l
428-
ld l, a
429-
ld a, h
430-
adc a, 0 ; f = f + ddF_x
431-
ld h, a
432-
pop af
433-
ex af, af'
434-
push bc
435-
exx
436-
pop hl ; H'L' = Y, X
437-
ld a, d
438-
add a, h
439-
ld b, a ; B = y0 + y
440-
ld a, e
441-
add a, l
442-
ld c, a ; C = x0 + x
443-
call __CIRCLE_PLOT ; plot(x0 + x, y0 + y)
444-
ld a, d
445-
add a, h
446-
ld b, a ; B = y0 + y
447-
ld a, e
448-
sub l
449-
ld c, a ; C = x0 - x
450-
call __CIRCLE_PLOT ; plot(x0 - x, y0 + y)
451-
ld a, d
452-
sub h
453-
ld b, a ; B = y0 - y
454-
ld a, e
455-
add a, l
456-
ld c, a ; C = x0 + x
457-
call __CIRCLE_PLOT ; plot(x0 + x, y0 - y)
458-
ld a, d
459-
sub h
460-
ld b, a ; B = y0 - y
461-
ld a, e
462-
sub l
463-
ld c, a ; C = x0 - x
464-
call __CIRCLE_PLOT ; plot(x0 - x, y0 - y)
465-
ld a, d
466-
add a, l
467-
ld b, a ; B = y0 + x
468-
ld a, e
469-
add a, h
470-
ld c, a ; C = x0 + y
471-
call __CIRCLE_PLOT ; plot(x0 + y, y0 + x)
472-
ld a, d
473-
add a, l
474-
ld b, a ; B = y0 + x
475-
ld a, e
476-
sub h
477-
ld c, a ; C = x0 - y
478-
call __CIRCLE_PLOT ; plot(x0 - y, y0 + x)
479-
ld a, d
480-
sub l
481-
ld b, a ; B = y0 - x
482-
ld a, e
483-
add a, h
484-
ld c, a ; C = x0 + y
485-
call __CIRCLE_PLOT ; plot(x0 + y, y0 - x)
486-
ld a, d
487-
sub l
488-
ld b, a ; B = y0 - x
489-
ld a, e
490-
sub h
491-
ld c, a ; C = x0 + y
492-
call __CIRCLE_PLOT ; plot(x0 - y, y0 - x)
493-
exx
494-
jp __CIRCLE_LOOP
419+
inc b ; x++
420+
ex af, af'
421+
add a, 2 ; 1 Cycle faster than inc a, inc a
422+
inc hl ; f++
423+
push af
424+
add a, l
425+
ld l, a
426+
ld a, h
427+
adc a, 0 ; f = f + ddF_x
428+
ld h, a
429+
pop af
430+
ex af, af'
431+
push bc
432+
exx
433+
pop hl ; H'L' = Y, X
434+
ld a, d
435+
add a, h
436+
ld b, a ; B = y0 + y
437+
ld a, e
438+
add a, l
439+
ld c, a ; C = x0 + x
440+
call __CIRCLE_PLOT ; plot(x0 + x, y0 + y)
441+
ld a, d
442+
add a, h
443+
ld b, a ; B = y0 + y
444+
ld a, e
445+
sub l
446+
ld c, a ; C = x0 - x
447+
call __CIRCLE_PLOT ; plot(x0 - x, y0 + y)
448+
ld a, d
449+
sub h
450+
ld b, a ; B = y0 - y
451+
ld a, e
452+
add a, l
453+
ld c, a ; C = x0 + x
454+
call __CIRCLE_PLOT ; plot(x0 + x, y0 - y)
455+
ld a, d
456+
sub h
457+
ld b, a ; B = y0 - y
458+
ld a, e
459+
sub l
460+
ld c, a ; C = x0 - x
461+
call __CIRCLE_PLOT ; plot(x0 - x, y0 - y)
462+
ld a, d
463+
add a, l
464+
ld b, a ; B = y0 + x
465+
ld a, e
466+
add a, h
467+
ld c, a ; C = x0 + y
468+
call __CIRCLE_PLOT ; plot(x0 + y, y0 + x)
469+
ld a, d
470+
add a, l
471+
ld b, a ; B = y0 + x
472+
ld a, e
473+
sub h
474+
ld c, a ; C = x0 - y
475+
call __CIRCLE_PLOT ; plot(x0 - y, y0 + x)
476+
ld a, d
477+
sub l
478+
ld b, a ; B = y0 - x
479+
ld a, e
480+
add a, h
481+
ld c, a ; C = x0 + y
482+
call __CIRCLE_PLOT ; plot(x0 + y, y0 - x)
483+
ld a, d
484+
sub l
485+
ld b, a ; B = y0 - x
486+
ld a, e
487+
sub h
488+
ld c, a ; C = x0 + y
489+
call __CIRCLE_PLOT ; plot(x0 - y, y0 - x)
490+
exx
491+
jp __CIRCLE_LOOP
495492
__CIRCLE_PLOT:
496-
; Plots a point of the circle, preserving HL and DE
497-
push hl
498-
push de
499-
call __PLOT
500-
pop de
501-
pop hl
502-
ret
503-
ENDP
493+
; Plots a point of the circle, preserving HL and DE
494+
push hl
495+
push de
496+
call __PLOT
497+
pop de
498+
pop hl
499+
ret
500+
ENDP
504501
#line 76 "circle.bas"
505502
#line 1 "ftou32reg.asm"
506503
#line 1 "neg32.asm"

0 commit comments

Comments
 (0)