diff --git a/src/lib/arch/zxnext/runtime/SP/CharLeft.asm b/src/lib/arch/zxnext/runtime/SP/CharLeft.asm index 641754bfa..0d19132f1 100644 --- a/src/lib/arch/zxnext/runtime/SP/CharLeft.asm +++ b/src/lib/arch/zxnext/runtime/SP/CharLeft.asm @@ -1,59 +1,8 @@ +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; CharLeft -; Alvin Albrecht 2002 -; - -;INCLUDE "SPconfig.def" -;XLIB SPCharLeft - -; Char Left -; -; Adjusts screen address HL to move one character to the left -; on the display. Start of line wraps to the previous row. -; -; enter: HL = valid screen address -; Carry reset -; exit : Carry = moved off screen -; HL = moves one character left, with line wrap -; used : AF, HL - -;IF !DISP_HIRES - - push namespace core - -SP.CharLeft: - ld a,l - dec l - or a - ret nz - ld a,h - sub $08 - ld h,a - cp $40 - ret - - pop namespace - - -;ELSE - -;.SPCharLeft -; ld a,h -; xor $20 -; ld h,a -; cp $58 -; ccf -; ret nc -; ld a,l -; dec l -; or a -; ret nz -; ld a,h -; sub $08 -; ld h,a -; and $18 -; cp $18 -; ccf -; ret +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -; ENDIF \ No newline at end of file +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/SP/CharRight.asm b/src/lib/arch/zxnext/runtime/SP/CharRight.asm index 1a47d84cb..52ce45186 100644 --- a/src/lib/arch/zxnext/runtime/SP/CharRight.asm +++ b/src/lib/arch/zxnext/runtime/SP/CharRight.asm @@ -1,54 +1,8 @@ +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; CharRight -; Alvin Albrecht 2002 -; - -;INCLUDE "SPconfig.def" -;XLIB SPCharRight - -; Char Right -; -; Adjusts screen address HL to move one character to the right -; on the display. End of line wraps to the next row. -; -; enter: HL = valid screen address -; Carry reset -; exit : Carry = moved off screen -; HL = moves one character right, with line wrap -; used : AF, HL - -;IF !DISP_HIRES - - push namespace core - -SP.CharRight: - inc l - ret nz - ld a,8 - add a,h - ld h,a - cp $58 - ccf - ret - - pop namespace - - -;ELSE - -;.SPCharRight -; ld a,h -; xor $20 -; ld h,a -; cp $58 -; ret nc -; inc l -; ret nz -; ld a,8 -; add a,h -; ld h,a -; cp $58 -; ccf -; ret +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -; ENDIF \ No newline at end of file +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/SP/GetScrnAddr.asm b/src/lib/arch/zxnext/runtime/SP/GetScrnAddr.asm index 21f9a4afc..faca1b505 100644 --- a/src/lib/arch/zxnext/runtime/SP/GetScrnAddr.asm +++ b/src/lib/arch/zxnext/runtime/SP/GetScrnAddr.asm @@ -1,62 +1,8 @@ +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; GetScrnAddr -; Alvin Albrecht 2002 -; - -; Get Screen Address -; -; Computes the screen address given a valid pixel coordinate. -; (0,0) is located at the top left corner of the screen. -; -; enter: h = y coord -; l = x coord -; In hi-res mode, Carry is most significant bit of x coord (0..511 pixels) -; exit : de = screen address, b = pixel mask -; uses : af, b, de, hl - - push namespace core - PROC - LOCAL rotloop, norotate - -SPGetScrnAddr: - ld a,h - and $07 - ld d,a - ld a,h - rra - rra - rra - and $18 - or d - ld d,a - - ld a,l - and $07 - ld b,a - ld a,$80 - jr z, norotate - -rotloop: - rra - djnz rotloop - -norotate: - ld b,a - srl l - srl l - srl l - ld a,h - rla - rla - and $e0 - or l - ld e,a - ld hl, (SCREEN_ADDR) - add hl, de - ex de, hl - ret - - ENDP - pop namespace +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -#include once +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/SP/PixelDown.asm b/src/lib/arch/zxnext/runtime/SP/PixelDown.asm index 3b5aaf62e..e644ae996 100644 --- a/src/lib/arch/zxnext/runtime/SP/PixelDown.asm +++ b/src/lib/arch/zxnext/runtime/SP/PixelDown.asm @@ -1,57 +1,8 @@ +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; PixelDown -; Alvin Albrecht 2002 -; - -; Pixel Down -; -; Adjusts screen address HL to move one pixel down in the display. -; (0,0) is located at the top left corner of the screen. -; -; enter: HL = valid screen address -; exit : Carry = moved off screen -; Carry'= moved off current cell (needs ATTR update) -; HL = moves one pixel down -; used : AF, HL - - push namespace core - -SP.PixelDown: - PROC - LOCAL leave - - push de - ld de, (SCREEN_ADDR) - or a - sbc hl, de - inc h - ld a,h - and $07 - jr nz, leave - scf ; Sets carry on F', which flags ATTR must be updated - ex af, af' - ld a,h - sub $08 - ld h,a - ld a,l - add a,$20 - ld l,a - jr nc, leave - ld a,h - add a,$08 - ld h,a - cp $19 ; carry = 0 => Out of screen - jr c, leave ; returns if out of screen - ccf - pop de - ret - -leave: - add hl, de ; This always sets Carry = 0 - pop de - ret - - ENDP - pop namespace +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -#include once \ No newline at end of file +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/SP/PixelLeft.asm b/src/lib/arch/zxnext/runtime/SP/PixelLeft.asm index 20be4e294..39f9fb9f3 100644 --- a/src/lib/arch/zxnext/runtime/SP/PixelLeft.asm +++ b/src/lib/arch/zxnext/runtime/SP/PixelLeft.asm @@ -1,52 +1,8 @@ +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; PixelLeft -; Jose Rodriguez 2012 -; - -; PixelLeft -; -; Adjusts screen address HL and Pixel bit A to move one pixel to the left -; on the display. Start of line set Carry (Out of Screen) -; -; enter: HL = valid screen address -; A = Bit Set -; exit : Carry = moved off screen -; Carry' Set if moved off current ATTR CELL -; HL = moves one character left, if needed -; A = Bit Set with new pixel pos. -; used : AF, HL - - - push namespace core - -SP.PixelLeft: - PROC - - LOCAL leave - - push de - ld de, (SCREEN_ADDR) - or a - sbc hl, de ; This always sets Carry = 0 - - rlca ; Sets new pixel bit 1 to the right - jr nc, leave - ex af, af' ; Signal in C' we've moved off current ATTR cell - ld a,l - dec a - ld l,a - cp 32 ; Carry if in screen - ccf - ld a, 1 - -leave: ; Sets screen offset back again - push af - add hl, de - pop af - pop de - ret - - ENDP - pop namespace +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -#include once +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/SP/PixelRight.asm b/src/lib/arch/zxnext/runtime/SP/PixelRight.asm index 5c0688e93..8d7e8eda4 100644 --- a/src/lib/arch/zxnext/runtime/SP/PixelRight.asm +++ b/src/lib/arch/zxnext/runtime/SP/PixelRight.asm @@ -1,53 +1,8 @@ +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; PixelRight -; Jose Rodriguez 2012 -; - - -; PixelRight -; -; Adjusts screen address HL and Pixel bit A to move one pixel to the left -; on the display. Start of line set Carry (Out of Screen) -; -; enter: HL = valid screen address -; A = Bit Set -; exit : Carry = moved off screen -; Carry' Set if moved off current ATTR CELL -; HL = moves one character left, if needed -; A = Bit Set with new pixel pos. -; used : AF, HL - - - push namespace core - -SP.PixelRight: - PROC - - LOCAL leave - - push de - ld de, (SCREEN_ADDR) - or a - sbc hl, de ; This always sets Carry = 0 - - rrca ; Sets new pixel bit 1 to the right - jr nc, leave - ex af, af' ; Signal in C' we've moved off current ATTR cell - ld a, l - inc a - ld l, a - cp 32 ; Carry if IN screen - ccf - ld a, 80h - -leave: ; Sets screen offset back again - push af - add hl, de - pop af - pop de - ret - - ENDP - pop namespace +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -#include once +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/SP/PixelUp.asm b/src/lib/arch/zxnext/runtime/SP/PixelUp.asm index 1657f9571..cd99f7998 100644 --- a/src/lib/arch/zxnext/runtime/SP/PixelUp.asm +++ b/src/lib/arch/zxnext/runtime/SP/PixelUp.asm @@ -1,56 +1,8 @@ +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; PixelUp -; Alvin Albrecht 2002 -; - -; Pixel Up -; -; Adjusts screen address HL to move one pixel up in the display. -; (0,0) is located at the top left corner of the screen. -; -; enter: HL = valid screen address -; exit : Carry = moved off screen -; HL = moves one pixel up -; used : AF, HL - - push namespace core - -SP.PixelUp: - PROC - - LOCAL leave - - push de - ld de, (SCREEN_ADDR) - or a - sbc hl, de - - ld a,h - dec h - and $07 - jr nz, leave - scf ; sets C' to 1 (ATTR update needed) - ex af, af' - ld a,$08 - add a,h - ld h,a - ld a,l - sub $20 - ld l,a - jr nc, leave - ld a,h - sub $08 - ld h,a - -leave: - push af - add hl, de - pop af - pop de - ret - - ENDP - - pop namespace +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -#include once +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/abs16.asm b/src/lib/arch/zxnext/runtime/abs16.asm index 08a7699ff..c0ea9bac3 100644 --- a/src/lib/arch/zxnext/runtime/abs16.asm +++ b/src/lib/arch/zxnext/runtime/abs16.asm @@ -1,5 +1,8 @@ -; 16 bit signed integer abs value -; HL = value - -#include once +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/abs32.asm b/src/lib/arch/zxnext/runtime/abs32.asm index 0ef7ebab3..1c24bcb97 100644 --- a/src/lib/arch/zxnext/runtime/abs32.asm +++ b/src/lib/arch/zxnext/runtime/abs32.asm @@ -1,5 +1,8 @@ -; 16 bit signed integer abs value -; HL = value - -#include once +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/abs8.asm b/src/lib/arch/zxnext/runtime/abs8.asm index 499c8efa0..21c135129 100644 --- a/src/lib/arch/zxnext/runtime/abs8.asm +++ b/src/lib/arch/zxnext/runtime/abs8.asm @@ -1,12 +1,8 @@ -; Returns absolute value for 8 bit signed integer +; ---------------------------------------------------------------- +; This file is released under the MIT License ; - push namespace core - -__ABS8: - or a - ret p - neg - ret - - pop namespace +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/absf.asm b/src/lib/arch/zxnext/runtime/absf.asm index 084e1d55f..a882ec4ab 100644 --- a/src/lib/arch/zxnext/runtime/absf.asm +++ b/src/lib/arch/zxnext/runtime/absf.asm @@ -1,8 +1,8 @@ -; ABS value for a floating point A EDCB - push namespace core +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -__ABSF: - res 7, e ; Sets sign to positive. Thast all! ;-) - ret - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/array/arrayalloc.asm b/src/lib/arch/zxnext/runtime/array/arrayalloc.asm index 705efe67b..609dc3184 100644 --- a/src/lib/arch/zxnext/runtime/array/arrayalloc.asm +++ b/src/lib/arch/zxnext/runtime/array/arrayalloc.asm @@ -1,143 +1,8 @@ - -#include once - - -; --------------------------------------------------------------------- -; __ALLOC_LOCAL_ARRAY -; Allocates an array element area in the heap, and clears it filling it -; with 0 bytes -; -; Parameters -; HL = Offset to be added to IX => HL = IX + HL -; BC = Length of the element area = n.elements * size(element) -; DE = PTR to the index table -; -; Returns: -; HL = (IX + HL) + 4 -; --------------------------------------------------------------------- - - push namespace core - -__ALLOC_LOCAL_ARRAY: - push de - push ix - pop de - add hl, de ; hl = ix + hl - pop de - ld (hl), e - inc hl - ld (hl), d - inc hl - push hl - call __MEM_CALLOC - pop de - ex de, hl - ld (hl), e - inc hl - ld (hl), d - ret - - -; --------------------------------------------------------------------- -; __ALLOC_INITIALIZED_LOCAL_ARRAY -; Allocates an array element area in the heap, and clears it filling it -; with data whose pointer (PTR) is in the stack -; -; Parameters -; HL = Offset to be added to IX => HL = IX + HL -; BC = Length of the element area = n.elements * size(element) -; DE = PTR to the index table -; [SP + 2] = PTR to the element area -; -; Returns: -; HL = (IX + HL) + 4 -; --------------------------------------------------------------------- - -__ALLOC_INITIALIZED_LOCAL_ARRAY: - push bc - call __ALLOC_LOCAL_ARRAY - pop bc - ;; Swaps [SP], [SP + 2] - exx - pop hl ; HL <- RET address - ex (sp), hl ; HL <- Data table, [SP] <- RET address - push hl ; [SP] <- Data table - exx - ex (sp), hl ; HL = Data table, (SP) = (IX + HL + 4) - start of array address lbound - ; HL = data table - ; BC = length - ; DE = new data area - ldir - pop hl ; HL = addr of LBound area if used - ret - - -#ifdef __ZXB_USE_LOCAL_ARRAY_WITH_BOUNDS__ - -; --------------------------------------------------------------------- -; __ALLOC_LOCAL_ARRAY_WITH_BOUNDS -; Allocates an array element area in the heap, and clears it filling it -; with 0 bytes. Then sets LBOUND and UBOUND ptrs -; -; Parameters -; HL = Offset to be added to IX => HL = IX + HL -; BC = Length of the element area = n.elements * size(element) -; DE = PTR to the index table -; [SP + 2] PTR to the lbound element area -; [SP + 4] PTR to the ubound element area +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Returns: -; HL = (IX + HL) + 8 -; --------------------------------------------------------------------- -__ALLOC_LOCAL_ARRAY_WITH_BOUNDS: - call __ALLOC_LOCAL_ARRAY - -__ALLOC_LOCAL_ARRAY_WITH_BOUNDS2: - pop bc ;; ret address - pop de ;; lbound - inc hl - ld (hl), e - inc hl - ld (hl), d - pop de ;; PTR to ubound table - push bc ;; puts ret address back - ld a, d - or e - ret z ;; if PTR for UBound is 0, it's not used - inc hl - ld (hl), e - inc hl - ld (hl), d - ret - - -; --------------------------------------------------------------------- -; __ALLOC_INITIALIZED_LOCAL_ARRAY_WITH_BOUNDS -; Allocates an array element area in the heap, and clears it filling it -; with 0 bytes -; -; Parameters -; HL = Offset to be added to IX => HL = IX + HL -; BC = Length of the element area = n.elements * size(element) -; DE = PTR to the index table -; TOP of the stack = PTR to the element area -; [SP + 2] = PTR to the element area -; [SP + 4] = PTR to the lbound element area -; [SP + 6] = PTR to the ubound element area -; -; Returns: -; HL = (IX + HL) + 8 -; --------------------------------------------------------------------- -__ALLOC_INITIALIZED_LOCAL_ARRAY_WITH_BOUNDS: - ;; Swaps [SP] and [SP + 2] - exx - pop hl ;; Ret address - ex (sp), hl ;; HL <- PTR to Element area, (sp) = Ret address - push hl ;; [SP] = PTR to element area, [SP + 2] = Ret address - exx - call __ALLOC_INITIALIZED_LOCAL_ARRAY - jp __ALLOC_LOCAL_ARRAY_WITH_BOUNDS2 - -#endif +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/array/arraybound.asm b/src/lib/arch/zxnext/runtime/array/arraybound.asm index 6cb71eafa..8a41bba74 100644 --- a/src/lib/arch/zxnext/runtime/array/arraybound.asm +++ b/src/lib/arch/zxnext/runtime/array/arraybound.asm @@ -1,91 +1,8 @@ -; --------------------------------------------------------- -; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel) -; http://www.boriel.com +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; ZX BASIC Compiler http://www.zxbasic.net -; This code is released under the BSD License -; --------------------------------------------------------- +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -; Implements both LBOUND(array, N) and UBOUND(array, N) function -; Parameters: -; HL = PTR to array -; [stack - 2] -> N (dimension) - - push namespace core - - PROC - LOCAL __BOUND - LOCAL __DIM_NOT_EXIST - LOCAL __CONT - -__LBOUND: - ld a, 4 - jr __BOUND - -__UBOUND: - ld a, 6 - -__BOUND: - ex de, hl ; DE <-- Array ptr - pop hl ; HL <-- Ret address - ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address - ex de, hl ; DE <-- N, HL <-- ARRAY_PTR - - push hl - ld c, (hl) - inc hl - ld h, (hl) - ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1) - ld c, (hl) - inc hl - ld b, (hl) - inc bc ; Number of total dimensions of the array - pop hl ; Recovers ARRAY PTR - ex af, af' ; Saves A for later - ld a, d - or e - jr nz, __CONT ; N = 0 => Return number of dimensions - - ;; Return the number of dimensions of the array - ld h, b - ld l, c - ret - -__CONT: - dec de - ex af, af' ; Recovers A (contains PTR offset) - ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR - or a - sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0 - jr nc, __DIM_NOT_EXIST - - add hl, bc ; restores HL = (N - 1) - add hl, hl ; hl *= 2 - ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2 - ld b, 0 - ld c, a - add hl, bc ; HL = &BOUND_PTR - ld a, (hl) - inc hl - ld h, (hl) - ld l, a ; LD HL, (HL) => Origin of L/U Bound table - - ; for LBound only, HL = 0x0000 (NULL) if the array is all 0-based - or h - ret z ; Should never happen for UBound - - add hl, de ; hl += OFFSET __LBOUND._xxxx - ld e, (hl) ; de = (hl) - inc hl - ld d, (hl) - - ex de, hl ; hl = de => returns result in HL - ret - -__DIM_NOT_EXIST: -; The dimension requested by the user does not exists. Return 0 - ld hl, 0 - ret - ENDP - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/array/arraystrfree.asm b/src/lib/arch/zxnext/runtime/array/arraystrfree.asm index c599ef6b7..8bcb32542 100644 --- a/src/lib/arch/zxnext/runtime/array/arraystrfree.asm +++ b/src/lib/arch/zxnext/runtime/array/arraystrfree.asm @@ -1,63 +1,8 @@ -; This routine is in charge of freeing an array of strings from memory -; HL = Pointer to start of array in memory -; Top of the stack = Number of elements of the array - -#include once - - push namespace core - -__ARRAYSTR_FREE: - PROC - - LOCAL __ARRAY_LOOP - - ex de, hl - pop hl ; (ret address) - ex (sp), hl ; Callee -> HL = Number of elements - - ex de, hl - -__ARRAYSTR_FREE_FAST: ; Fastcall entry: DE = Number of elements - ld a, h - or l - ret z ; ret if NULL - - ld b, d - ld c, e - -__ARRAY_LOOP: - ld e, (hl) - inc hl - ld d, (hl) - inc hl ; DE = (HL) = String Pointer - - push hl - push bc - ex de, hl - call __MEM_FREE ; Frees it from memory - pop bc - pop hl - - dec bc - ld a, b - or c - jp nz, __ARRAY_LOOP - - ret ; Frees it and return - - ENDP - - -__ARRAYSTR_FREE_MEM: ; like the above, buf also frees the array itself - ex de, hl - pop hl ; (ret address) - ex (sp), hl ; Callee -> HL = Number of elements - ex de, hl - - push hl ; Saves array pointer for later - call __ARRAYSTR_FREE_FAST - pop hl ; recovers array block pointer - - jp __MEM_FREE ; Frees it and returns from __MEM_FREE - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/array/strarraycpy.asm b/src/lib/arch/zxnext/runtime/array/strarraycpy.asm index aafc51426..69ba6b8f0 100644 --- a/src/lib/arch/zxnext/runtime/array/strarraycpy.asm +++ b/src/lib/arch/zxnext/runtime/array/strarraycpy.asm @@ -1,68 +1,8 @@ -; (K)opyleft - by Jose M. Rodriguez de la Rosa (a.k.a. Boriel) -; 2009 - This is Free OpenSource BSD code -; vim: et:ts=4:sw=4 - -; Copies a vector of strings from one place to another -; reallocating strings of the destiny vector to hold source strings. -; This is used in the following code: -; DIM a$(20) : DIM b$(20): a$ = b$ - -#include once -#include once - - push namespace core - -STR_ARRAYCOPY: -; Copies an array of string a$ = b$ -; Parameters in the stack: -; a$, b$, num. of elements; - pop hl ; ret address - pop bc ; num of elements - pop de ; source array + offset to the 1st elem. - ex (sp), hl ; Callee -> hl = destiny array + offset to the 1st elem. - -; FASTCALL ENTRY - -; HL = a$ + offset -; DE = b$ + offset -; BC = Number of elements - -__STR_ARRAYCOPY: - PROC - LOCAL LOOP - -LOOP: - ld a, b - or c - ret z ; Done! - - dec bc - push bc - push de - - ld a,(hl) - inc hl - ld c,(hl) - dec hl - push hl - - ld h, c - ld l, a - call __LOAD_DE_DE - call __STRASSIGN - - ex de, hl - pop hl - ld (hl), e - inc hl - ld (hl), d - inc hl - pop de - pop bc - inc de - inc de - jp LOOP - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/asc.asm b/src/lib/arch/zxnext/runtime/asc.asm index 91f98fc2c..71251f381 100644 --- a/src/lib/arch/zxnext/runtime/asc.asm +++ b/src/lib/arch/zxnext/runtime/asc.asm @@ -1,39 +1,8 @@ -; Returns the ascii code for the given str -#include once - - push namespace core - -__ASC: - PROC - LOCAL __ASC_END - - ex af, af' ; Saves free_mem flag - - ld a, h - or l - ret z ; NULL? return - - ld c, (hl) - inc hl - ld b, (hl) - - ld a, b - or c - jr z, __ASC_END ; No length? return - - inc hl - ld a, (hl) - dec hl - -__ASC_END: - dec hl - ex af, af' - or a - call nz, __MEM_FREE ; Free memory if needed - - ex af, af' ; Recover result - - ret - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/attr.asm b/src/lib/arch/zxnext/runtime/attr.asm index 7c228409b..7e2603c9f 100644 --- a/src/lib/arch/zxnext/runtime/attr.asm +++ b/src/lib/arch/zxnext/runtime/attr.asm @@ -1,65 +1,8 @@ -; Attribute routines -; vim:ts=4:et:sw: - -#include once -#include once -#include once -#include once - - push namespace core - -__ATTR_ADDR: - ; calc start address in DE (as (32 * d) + e) - ; Contributed by Santiago Romero at http://www.speccy.org - ld h, 0 ; 7 T-States - ld a, d ; 4 T-States - ld d, h - add a, a ; a * 2 ; 4 T-States - add a, a ; a * 4 ; 4 T-States - ld l, a ; HL = A * 4 ; 4 T-States - - add hl, hl ; HL = A * 8 ; 15 T-States - add hl, hl ; HL = A * 16 ; 15 T-States - add hl, hl ; HL = A * 32 ; 15 T-States - add hl, de - - ld de, (SCREEN_ATTR_ADDR) ; Adds the screen address - add hl, de - ; Return current screen address in HL - ret - - -; Sets the attribute at a given screen coordinate (D, E). -; The attribute is taken from the ATTR_T memory variable -; Used by PRINT routines -SET_ATTR: - - ; Checks for valid coords - call __IN_SCREEN - ret nc - - call __ATTR_ADDR - -__SET_ATTR: - ; Internal __FASTCALL__ Entry used by printing routines - ; HL contains the address of the ATTR cell to set - PROC - -__SET_ATTR2: ; Sets attr from ATTR_T to (HL) which points to the scr address - ld de, (ATTR_T) ; E = ATTR_T, D = MASK_T - - ld a, d - and (hl) - ld c, a ; C = current screen color, masked - - ld a, d - cpl ; Negate mask - and e ; Mask current attributes - or c ; Mix them - ld (hl), a ; Store result in screen - - ret - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bitwise/band16.asm b/src/lib/arch/zxnext/runtime/bitwise/band16.asm index a7ff382ca..ed946504c 100644 --- a/src/lib/arch/zxnext/runtime/bitwise/band16.asm +++ b/src/lib/arch/zxnext/runtime/bitwise/band16.asm @@ -1,22 +1,8 @@ -; vim:ts=4:et: -; FASTCALL bitwise and16 version. -; result in hl -; __FASTCALL__ version (operands: A, H) -; Performs 16bit or 16bit and returns the boolean -; Input: HL, DE -; Output: HL <- HL AND DE - - push namespace core - -__BAND16: - ld a, h - and d - ld h, a - - ld a, l - and e - ld l, a - - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bitwise/band32.asm b/src/lib/arch/zxnext/runtime/bitwise/band32.asm index 311c37b67..9cb96c546 100644 --- a/src/lib/arch/zxnext/runtime/bitwise/band32.asm +++ b/src/lib/arch/zxnext/runtime/bitwise/band32.asm @@ -1,39 +1,8 @@ -; FASTCALL bitwise and 32 version. -; Performs 32bit and 32bit and returns the bitwise -; result in DE,HL -; First operand in DE,HL 2nd operand into the stack - - push namespace core - -__BAND32: - ld b, h - ld c, l ; BC <- HL - - pop hl ; Return address - ex (sp), hl ; HL <- Lower part of 2nd Operand - - ld a, b - and h - ld b, a - - ld a, c - and l - ld c, a ; BC <- BC & HL - - pop hl ; Return dddress - ex (sp), hl ; HL <- High part of 2nd Operand - - ld a, d - and h - ld d, a - - ld a, e - and l - ld e, a ; DE <- DE & HL - - ld h, b - ld l, c ; HL <- BC ; Always return DE,HL pair regs - - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bitwise/bnot16.asm b/src/lib/arch/zxnext/runtime/bitwise/bnot16.asm index b1b8ffe63..37081941e 100644 --- a/src/lib/arch/zxnext/runtime/bitwise/bnot16.asm +++ b/src/lib/arch/zxnext/runtime/bitwise/bnot16.asm @@ -1,22 +1,8 @@ -; vim:ts=4:et: -; FASTCALL bitwise or 16 version. -; result in HL -; __FASTCALL__ version (operands: A, H) -; Performs 16bit NEGATION -; Input: HL -; Output: HL <- NOT HL - - push namespace core - -__BNOT16: - ld a, h - cpl - ld h, a - - ld a, l - cpl - ld l, a - - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bitwise/bnot32.asm b/src/lib/arch/zxnext/runtime/bitwise/bnot32.asm index 243870646..89cd6d343 100644 --- a/src/lib/arch/zxnext/runtime/bitwise/bnot32.asm +++ b/src/lib/arch/zxnext/runtime/bitwise/bnot32.asm @@ -1,30 +1,8 @@ -; vim:ts=4:et: -; FASTCALL bitwise or 32 version. -; result in DE,HL -; __FASTCALL__ version (operands: A, H) -; Performs 32bit NEGATION (cpl) -; Input: DE,HL -; Output: DE,HL <- NOT DE,HL - - push namespace core - -__BNOT32: - ld a, l - cpl - ld l, a - - ld a, h - cpl - ld h, a - - ld a, e - cpl - ld e, a - - ld a, d - cpl - ld d, a - - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bitwise/bor16.asm b/src/lib/arch/zxnext/runtime/bitwise/bor16.asm index 03fd45db8..574bdc887 100644 --- a/src/lib/arch/zxnext/runtime/bitwise/bor16.asm +++ b/src/lib/arch/zxnext/runtime/bitwise/bor16.asm @@ -1,22 +1,8 @@ -; vim:ts=4:et: -; FASTCALL bitwise or 16 version. -; result in HL -; __FASTCALL__ version (operands: A, H) -; Performs 16bit or 16bit and returns the boolean -; Input: HL, DE -; Output: HL <- HL OR DE - - push namespace core - -__BOR16: - ld a, h - or d - ld h, a - - ld a, l - or e - ld l, a - - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bitwise/bor32.asm b/src/lib/arch/zxnext/runtime/bitwise/bor32.asm index 470578b2f..46ee69a99 100644 --- a/src/lib/arch/zxnext/runtime/bitwise/bor32.asm +++ b/src/lib/arch/zxnext/runtime/bitwise/bor32.asm @@ -1,39 +1,8 @@ -; FASTCALL bitwise or 32 version. -; Performs 32bit or 32bit and returns the bitwise -; result DE,HL -; First operand in DE,HL 2nd operand into the stack - - push namespace core - -__BOR32: - ld b, h - ld c, l ; BC <- HL - - pop hl ; Return address - ex (sp), hl ; HL <- Lower part of 2nd Operand - - ld a, b - or h - ld b, a - - ld a, c - or l - ld c, a ; BC <- BC & HL - - pop hl ; Return dddress - ex (sp), hl ; HL <- High part of 2nd Operand - - ld a, d - or h - ld d, a - - ld a, e - or l - ld e, a ; DE <- DE & HL - - ld h, b - ld l, c ; HL <- BC ; Always return DE,HL pair regs - - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bitwise/bxor16.asm b/src/lib/arch/zxnext/runtime/bitwise/bxor16.asm index 297d853e4..c4ece6616 100644 --- a/src/lib/arch/zxnext/runtime/bitwise/bxor16.asm +++ b/src/lib/arch/zxnext/runtime/bitwise/bxor16.asm @@ -1,22 +1,8 @@ -; vim:ts=4:et: -; FASTCALL bitwise xor 16 version. -; result in Accumulator (0 False, not 0 True) -; __FASTCALL__ version (operands: A, H) -; Performs 16bit xor 16bit and returns the boolean -; Input: HL, DE -; Output: HL <- HL XOR DE - - push namespace core - -__BXOR16: - ld a, h - xor d - ld h, a - - ld a, l - xor e - ld l, a - - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bitwise/bxor32.asm b/src/lib/arch/zxnext/runtime/bitwise/bxor32.asm index d0100f704..52d2b2fa8 100644 --- a/src/lib/arch/zxnext/runtime/bitwise/bxor32.asm +++ b/src/lib/arch/zxnext/runtime/bitwise/bxor32.asm @@ -1,39 +1,8 @@ -; FASTCALL bitwise xor 32 version. -; Performs 32bit xor 32bit and returns the bitwise -; result DE,HL -; First operand in DE,HL 2nd operand into the stack - - push namespace core - -__BXOR32: - ld b, h - ld c, l ; BC <- HL - - pop hl ; Return address - ex (sp), hl ; HL <- Lower part of 2nd Operand - - ld a, b - xor h - ld b, a - - ld a, c - xor l - ld c, a ; BC <- BC & HL - - pop hl ; Return address - ex (sp), hl ; HL <- High part of 2nd Operand - - ld a, d - xor h - ld d, a - - ld a, e - xor l - ld e, a ; DE <- DE & HL - - ld h, b - ld l, c ; HL <- BC ; Always return DE,HL pair regs - - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bitwise/shl32.asm b/src/lib/arch/zxnext/runtime/bitwise/shl32.asm index 253884079..1769af86b 100644 --- a/src/lib/arch/zxnext/runtime/bitwise/shl32.asm +++ b/src/lib/arch/zxnext/runtime/bitwise/shl32.asm @@ -1,12 +1,8 @@ - - push namespace core - -__SHL32: ; Left Logical Shift 32 bits - - sla l - rl h - rl e - rl d - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bitwise/shra32.asm b/src/lib/arch/zxnext/runtime/bitwise/shra32.asm index 7f7257a1f..5ede8796a 100644 --- a/src/lib/arch/zxnext/runtime/bitwise/shra32.asm +++ b/src/lib/arch/zxnext/runtime/bitwise/shra32.asm @@ -1,12 +1,8 @@ - - push namespace core - -__SHRA32: ; Right Arithmetical Shift 32 bits - - sra d - rr e - rr h - rr l - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bitwise/shrl32.asm b/src/lib/arch/zxnext/runtime/bitwise/shrl32.asm index 1de12b689..54fabad65 100644 --- a/src/lib/arch/zxnext/runtime/bitwise/shrl32.asm +++ b/src/lib/arch/zxnext/runtime/bitwise/shrl32.asm @@ -1,12 +1,8 @@ - - push namespace core - -__SHRL32: ; Right Logical Shift 32 bits - - srl d - rr e - rr h - rr l - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bold.asm b/src/lib/arch/zxnext/runtime/bold.asm index 4bd46a82e..010169c6c 100644 --- a/src/lib/arch/zxnext/runtime/bold.asm +++ b/src/lib/arch/zxnext/runtime/bold.asm @@ -1,34 +1,8 @@ -; Sets BOLD flag in P_FLAG permanently -; Parameter: BOLD flag in bit 0 of A register -#include once - - push namespace core - -BOLD: - PROC - - and 1 - rlca - rlca - rlca - ld hl, FLAGS2 - res 3, (HL) - or (hl) - ld (hl), a - ret - -; Sets BOLD flag in P_FLAG temporarily -BOLD_TMP: - and 1 - rlca - rlca - ld hl, FLAGS2 - res 2, (hl) - or (hl) - ld (hl), a - ret - - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bool/and16.asm b/src/lib/arch/zxnext/runtime/bool/and16.asm index 829a0bb9b..9a5b3339f 100644 --- a/src/lib/arch/zxnext/runtime/bool/and16.asm +++ b/src/lib/arch/zxnext/runtime/bool/and16.asm @@ -1,17 +1,8 @@ -; FASTCALL boolean and 16 version. -; result in Accumulator (0 False, not 0 True) -; __FASTCALL__ version (operands: DE, HL) -; Performs 16bit and 16bit and returns the boolean - - push namespace core - -__AND16: - ld a, h - or l - ret z - - ld a, d - or e - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bool/and32.asm b/src/lib/arch/zxnext/runtime/bool/and32.asm index 9723308a1..5ff61e206 100644 --- a/src/lib/arch/zxnext/runtime/bool/and32.asm +++ b/src/lib/arch/zxnext/runtime/bool/and32.asm @@ -1,31 +1,8 @@ -; FASTCALL boolean and 32 version. -; Performs 32bit and 32bit and returns the boolean -; result in Accumulator (0 False, not 0 True) -; First operand in DE,HL 2nd operand into the stack - - push namespace core - -__AND32: - ld a, l - or h - or e - or d - - pop hl - pop de - ex (sp), hl - ret z - - ld a, d - or e - or h - or l - -#ifdef NORMALIZE_BOOLEAN - ret z - ld a, 1 -#endif - - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bool/andf.asm b/src/lib/arch/zxnext/runtime/bool/andf.asm index fabbc00e6..5bb0c6a0c 100644 --- a/src/lib/arch/zxnext/runtime/bool/andf.asm +++ b/src/lib/arch/zxnext/runtime/bool/andf.asm @@ -1,28 +1,8 @@ -#include once -#include once -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses C EDHL registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order BC DE HL (B not used). +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Uses CALLEE convention -; ------------------------------------------------------------- - - push namespace core - -__ANDF: ; A & B - call __FPSTACK_PUSH2 - - ; ------------- ROM NO-&-NO - rst 28h - defb 08h ; - defb 38h; ; END CALC - - call __FPSTACK_POP - jp __FTOU8 ; Convert to 8 bits +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bool/not32.asm b/src/lib/arch/zxnext/runtime/bool/not32.asm index e354698ed..8493e7560 100644 --- a/src/lib/arch/zxnext/runtime/bool/not32.asm +++ b/src/lib/arch/zxnext/runtime/bool/not32.asm @@ -1,16 +1,8 @@ -; ------------------------------------------------------------- -; 32 bit logical NOT -; ------------------------------------------------------------- +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - push namespace core - -__NOT32: ; A = ¬A - ld a, d - or e - or h - or l - sub 1 ; Gives CARRY only if 0 - sbc a, a; Gives 0 if not carry, FF otherwise - ret - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bool/notf.asm b/src/lib/arch/zxnext/runtime/bool/notf.asm index bced6ef9f..0838ee0ab 100644 --- a/src/lib/arch/zxnext/runtime/bool/notf.asm +++ b/src/lib/arch/zxnext/runtime/bool/notf.asm @@ -1,28 +1,8 @@ -#include once -#include once -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses C EDHL registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order BC DE HL (B not used). +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Uses CALLEE convention -; ------------------------------------------------------------- - - push namespace core - -__NOTF: ; A = ¬A - call __FPSTACK_PUSH - - ; ------------- ROM NOT - rst 28h - defb 30h ; - defb 38h; ; END CALC - - call __FPSTACK_POP - jp __FTOU8 ; Convert to 8 bits +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bool/or32.asm b/src/lib/arch/zxnext/runtime/bool/or32.asm index e1cb1689b..b83f5ba9e 100644 --- a/src/lib/arch/zxnext/runtime/bool/or32.asm +++ b/src/lib/arch/zxnext/runtime/bool/or32.asm @@ -1,28 +1,8 @@ - push namespace core - -__OR32: ; Performs logical operation A AND B - ; between DEHL and TOP of the stack. - ; Returns A = 0 (False) or A = FF (True) - - ld a, h - or l - or d - or e - - pop hl ; Return address - pop de - ex (sp), hl - - or d - or e - or h - or l - -#ifdef NORMALIZE_BOOLEAN - ; Ensure it returns 0 or 1 - ret z - ld a, 1 -#endif - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bool/orf.asm b/src/lib/arch/zxnext/runtime/bool/orf.asm index 7a89a2bf6..8aef1bc4a 100644 --- a/src/lib/arch/zxnext/runtime/bool/orf.asm +++ b/src/lib/arch/zxnext/runtime/bool/orf.asm @@ -1,28 +1,8 @@ -#include once -#include once -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses A EDCb registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order A DE BC. +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Uses CALLEE convention -; ------------------------------------------------------------- - - push namespace core - -__ORF: ; A | B - call __FPSTACK_PUSH2 - - ; ------------- ROM NO-OR-NO - rst 28h - defb 07h ; - defb 38h; ; END CALC - - call __FPSTACK_POP - jp __FTOU8 ; Convert to 32 bits +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bool/xor16.asm b/src/lib/arch/zxnext/runtime/bool/xor16.asm index 85b1b3288..21978e818 100644 --- a/src/lib/arch/zxnext/runtime/bool/xor16.asm +++ b/src/lib/arch/zxnext/runtime/bool/xor16.asm @@ -1,3 +1,8 @@ +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -; XOR16 implemented in XOR8.ASM file -#include once +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bool/xor32.asm b/src/lib/arch/zxnext/runtime/bool/xor32.asm index 4be3918d5..c8dbed260 100644 --- a/src/lib/arch/zxnext/runtime/bool/xor32.asm +++ b/src/lib/arch/zxnext/runtime/bool/xor32.asm @@ -1,27 +1,8 @@ -; FASTCALL boolean xor 8 version. -; result in Accumulator (0 False, not 0 True) -; __FASTCALL__ version (operands: A, H) -; Performs 32bit xor 32bit and returns the boolean - -#include once - - push namespace core - -__XOR32: - ld a, h - or l - or d - or e - ld c, a - - pop hl ; RET address - pop de - ex (sp), hl - ld a, h - or l - or d - or e - ld h, c - jp __XOR8 - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bool/xor8.asm b/src/lib/arch/zxnext/runtime/bool/xor8.asm index a40d24729..c9285f95c 100644 --- a/src/lib/arch/zxnext/runtime/bool/xor8.asm +++ b/src/lib/arch/zxnext/runtime/bool/xor8.asm @@ -1,28 +1,8 @@ -; vim:ts=4:et: -; FASTCALL boolean xor 8 version. -; result in Accumulator (0 False, not 0 True) -; __FASTCALL__ version (operands: A, H) -; Performs 8bit xor 8bit and returns the boolean - - push namespace core - -__XOR16: - ld a, h - or l - ld h, a - - ld a, d - or e - -__XOR8: - sub 1 - sbc a, a - ld l, a ; l = 00h or FFh - - ld a, h - sub 1 - sbc a, a ; a = 00h or FFh - xor l - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bool/xorf.asm b/src/lib/arch/zxnext/runtime/bool/xorf.asm index 0c76f6f83..95d051682 100644 --- a/src/lib/arch/zxnext/runtime/bool/xorf.asm +++ b/src/lib/arch/zxnext/runtime/bool/xorf.asm @@ -1,38 +1,8 @@ -#include once -#include once -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses C EDHL registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order BC DE HL (B not used). +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Uses CALLEE convention -; ------------------------------------------------------------- - - push namespace core - -__XORF: ; A XOR B - call __FPSTACK_PUSH2 - - ; A XOR B == A ^ ¬B v ¬A ^ B - rst 28h - defb 0C0h ; STORE 0 - defb 02h ; DELETE - defb 31h ; DUP - defb 30h ; NOT A - defb 0E0h ; Recall 0 - defb 08h ; AND - defb 01h ; SWAP - defb 0E0h ; Recall 0 - defb 30h ; NOT B - defb 08h ; AND - defb 07h ; OR - defb 38h ; END CALC - - call __FPSTACK_POP - jp __FTOU8 ; Convert to 8 bits +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/border.asm b/src/lib/arch/zxnext/runtime/border.asm index 19c923194..3e46fd9f5 100644 --- a/src/lib/arch/zxnext/runtime/border.asm +++ b/src/lib/arch/zxnext/runtime/border.asm @@ -1,11 +1,8 @@ -; __FASTCALL__ Routine to change de border -; Parameter (color) specified in A register - - push namespace core - -BORDER EQU 229Bh - - pop namespace - - -; Nothing to do! (Directly from the ZX Spectrum ROM) +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/break.asm b/src/lib/arch/zxnext/runtime/break.asm index 9579232d5..f2f9ca23e 100644 --- a/src/lib/arch/zxnext/runtime/break.asm +++ b/src/lib/arch/zxnext/runtime/break.asm @@ -1,35 +1,8 @@ -#include once - - -; Check if BREAK is pressed -; Return if not. Else Raises -; L BREAK Into Program Error -; HL contains the line number we want to appear in the error msg. - - push namespace core - -CHECK_BREAK: - PROC - LOCAL PPC, TS_BRK, NO_BREAK - - push af - call TS_BRK - jr c, NO_BREAK - - ld (PPC), hl ; line num - ld a, ERROR_BreakIntoProgram - jp __ERROR ; this stops the program and exits to BASIC - -NO_BREAK: - pop af - pop hl ; ret address - ex (sp), hl ; puts it back into the stack and recovers initial HL - ret - -PPC EQU 23621 -TS_BRK EQU 8020 - - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/bright.asm b/src/lib/arch/zxnext/runtime/bright.asm index 13feb8fd4..75f8531c7 100644 --- a/src/lib/arch/zxnext/runtime/bright.asm +++ b/src/lib/arch/zxnext/runtime/bright.asm @@ -1,46 +1,8 @@ -; Sets bright flag in ATTR_P permanently -; Parameter: Paper color in A register - -#include once - - push namespace core - -BRIGHT: - ld hl, ATTR_P - - PROC - LOCAL IS_TR - LOCAL IS_ZERO - -__SET_BRIGHT: - ; Another entry. This will set the bright flag at location pointer by DE - cp 8 - jr z, IS_TR - - ; # Convert to 0/1 - or a - jr z, IS_ZERO - ld a, 0x40 - -IS_ZERO: - ld b, a ; Saves the color - ld a, (hl) - and 0BFh ; Clears previous value - or b - ld (hl), a - inc hl - res 6, (hl) ;Reset bit 6 to disable transparency - ret - -IS_TR: ; transparent - inc hl ; Points DE to MASK_T or MASK_P - set 6, (hl) ;Set bit 6 to enable transparency - ret - -; Sets the BRIGHT flag passed in A register in the ATTR_T variable -BRIGHT_TMP: - ld hl, ATTR_T - jr __SET_BRIGHT - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/chr.asm b/src/lib/arch/zxnext/runtime/chr.asm index 494285dc8..b2c6ecf77 100644 --- a/src/lib/arch/zxnext/runtime/chr.asm +++ b/src/lib/arch/zxnext/runtime/chr.asm @@ -1,78 +1,8 @@ -; CHR$(x, y, x) returns the string CHR$(x) + CHR$(y) + CHR$(z) +; ---------------------------------------------------------------- +; This file is released under the MIT License ; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -#include once - - push namespace core - -CHR: ; Returns HL = Pointer to STRING (NULL if no memory) - ; Requires alloc.asm for dynamic memory heap. - ; Parameters: HL = Number of bytes to insert (already push onto the stack) - ; STACK => parameters (16 bit, only the High byte is considered) - ; Used registers A, A', BC, DE, HL, H'L' - - PROC - - LOCAL __POPOUT - LOCAL TMP - -TMP EQU 23629 ; (DEST System variable) - - ld a, h - or l - ret z ; If Number of parameters is ZERO, return NULL STRING - - ld b, h - ld c, l - - pop hl ; Return address - ld (TMP), hl - - push bc - inc bc - inc bc ; BC = BC + 2 => (2 bytes for the length number) - call __MEM_ALLOC - pop bc - - ld d, h - ld e, l ; Saves HL in DE - - ld a, h - or l - jr z, __POPOUT ; No Memory, return - - ld (hl), c - inc hl - ld (hl), b - inc hl - -__POPOUT: ; Removes out of the stack every byte and return - ; If Zero Flag is set, don't store bytes in memory - ex af, af' ; Save Zero Flag - - ld a, b - or c - jr z, __CHR_END - - dec bc - pop af ; Next byte - - ex af, af' ; Recovers Zero flag - jr z, __POPOUT - - ex af, af' ; Saves Zero flag - ld (hl), a - inc hl - ex af, af' ; Recovers Zero Flag - - jp __POPOUT - -__CHR_END: - ld hl, (TMP) - push hl ; Restores return addr - ex de, hl ; Recovers original HL ptr - ret - - ENDP - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/circle.asm b/src/lib/arch/zxnext/runtime/circle.asm index 874b58ebe..3ab80a796 100644 --- a/src/lib/arch/zxnext/runtime/circle.asm +++ b/src/lib/arch/zxnext/runtime/circle.asm @@ -1,227 +1,8 @@ -; Bresenham's like circle algorithm -; best known as Middle Point Circle drawing algorithm - -#include once -#include once -#include once - -; Draws a circle at X, Y of radius R -; X, Y on the Stack, R in accumulator (Byte) - - push namespace core - - PROC - LOCAL __CIRCLE_ERROR - LOCAL __CIRCLE_LOOP - LOCAL __CIRCLE_NEXT - -__CIRCLE_ERROR: - jp __OUT_OF_SCREEN_ERR -CIRCLE: - ;; Entry point - pop hl ; Return Address - pop de ; D = Y - ex (sp), hl ; __CALLEE__ convention - ld e, h ; E = X - ld h, a ; H = R - -#ifdef SCREEN_Y_OFFSET - ld a, SCREEN_Y_OFFSET - add a, d - ld d, a -#endif - -#ifdef SCREEN_X_OFFSET - ld a, SCREEN_X_OFFSET - add a, e - ld e, a -#endif - - ld a, h - add a, d - sub 192 - jr nc, __CIRCLE_ERROR - - ld a, d - sub h - jr c, __CIRCLE_ERROR - - ld a, e - sub h - jr c, __CIRCLE_ERROR - - ld a, h - add a, e - jr c, __CIRCLE_ERROR - - -; __FASTCALL__ Entry: D, E = Y, X point of the center -; A = Radious -__CIRCLE: - push de - ld a, h - exx - pop de ; D'E' = x0, y0 - ld h, a ; H' = r - - ld c, e - ld a, h - add a, d - ld b, a - call __CIRCLE_PLOT ; PLOT (x0, y0 + r) - - ld b, d - ld a, h - add a, e - ld c, a - call __CIRCLE_PLOT ; PLOT (x0 + r, y0) - - ld c, e - ld a, d - sub h - ld b, a - call __CIRCLE_PLOT ; PLOT (x0, y0 - r) - - ld b, d - ld a, e - sub h - ld c, a - call __CIRCLE_PLOT ; PLOT (x0 - r, y0) - - exx - ld b, 0 ; B = x = 0 - ld c, h ; C = y = Radius - ld hl, 1 - or a - sbc hl, bc ; HL = f = 1 - radius - - ex de, hl - ld hl, 0 - or a - sbc hl, bc ; HL = -radius - add hl, hl ; HL = -2 * radius - ex de, hl ; DE = -2 * radius = ddF_y, HL = f - - xor a ; A = ddF_x = 0 - ex af, af' ; Saves it - -__CIRCLE_LOOP: - ld a, b - inc a - cp c - ret nc ; Returns when x >= y - - bit 7, h ; HL >= 0? : if (f >= 0)... - jp nz, __CIRCLE_NEXT - - dec c ; y-- - inc de - inc de ; ddF_y += 2 - - add hl, de ; f += ddF_y - -__CIRCLE_NEXT: - inc b ; x++ - ex af, af' - add a, 2 ; 1 Cycle faster than inc a, inc a - - inc hl ; f++ - push af - add a, l - ld l, a - ld a, h - adc a, 0 ; f = f + ddF_x - ld h, a - pop af - ex af, af' - - push bc - exx - pop hl ; H'L' = Y, X - - ld a, d - add a, h - ld b, a ; B = y0 + y - ld a, e - add a, l - ld c, a ; C = x0 + x - call __CIRCLE_PLOT ; plot(x0 + x, y0 + y) - - ld a, d - add a, h - ld b, a ; B = y0 + y - ld a, e - sub l - ld c, a ; C = x0 - x - call __CIRCLE_PLOT ; plot(x0 - x, y0 + y) - - ld a, d - sub h - ld b, a ; B = y0 - y - ld a, e - add a, l - ld c, a ; C = x0 + x - call __CIRCLE_PLOT ; plot(x0 + x, y0 - y) - - ld a, d - sub h - ld b, a ; B = y0 - y - ld a, e - sub l - ld c, a ; C = x0 - x - call __CIRCLE_PLOT ; plot(x0 - x, y0 - y) - - ld a, l - cp h - jr z, 1f - - ld a, d - add a, l - ld b, a ; B = y0 + x - ld a, e - add a, h - ld c, a ; C = x0 + y - call __CIRCLE_PLOT ; plot(x0 + y, y0 + x) - - ld a, d - add a, l - ld b, a ; B = y0 + x - ld a, e - sub h - ld c, a ; C = x0 - y - call __CIRCLE_PLOT ; plot(x0 - y, y0 + x) - - ld a, d - sub l - ld b, a ; B = y0 - x - ld a, e - add a, h - ld c, a ; C = x0 + y - call __CIRCLE_PLOT ; plot(x0 + y, y0 - x) - - ld a, d - sub l - ld b, a ; B = y0 - x - ld a, e - sub h - ld c, a ; C = x0 + y - call __CIRCLE_PLOT ; plot(x0 - y, y0 - x) - -1: - exx - jp __CIRCLE_LOOP - - - -__CIRCLE_PLOT: - ; Plots a point of the circle, preserving HL and DE - push hl - push de - call __PLOT - pop de - pop hl - ret - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cls.asm b/src/lib/arch/zxnext/runtime/cls.asm index 21aab73c8..24a28bc23 100644 --- a/src/lib/arch/zxnext/runtime/cls.asm +++ b/src/lib/arch/zxnext/runtime/cls.asm @@ -1,38 +1,8 @@ -;; Clears the user screen (24 rows) - -#include once - - push namespace core - -CLS: - PROC - - ld hl, 0 - ld (COORDS), hl - ld hl, SCR_SIZE - ld (S_POSN), hl - ld hl, (SCREEN_ADDR) - ld (DFCC), hl - ld (hl), 0 - ld d, h - ld e, l - inc de - ld bc, 6143 - ldir - - ; Now clear attributes - - ld hl, (SCREEN_ATTR_ADDR) - ld (DFCCL), hl - ld d, h - ld e, l - inc de - ld a, (ATTR_P) - ld (hl), a - ld bc, 767 - ldir - ret - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/eq16.asm b/src/lib/arch/zxnext/runtime/cmp/eq16.asm index 85bbdf440..e68d92931 100644 --- a/src/lib/arch/zxnext/runtime/cmp/eq16.asm +++ b/src/lib/arch/zxnext/runtime/cmp/eq16.asm @@ -1,11 +1,8 @@ - push namespace core +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -__EQ16: ; Test if 16bit values HL == DE - ; Returns result in A: 0 = False, FF = True - xor a ; Reset carry flag - sbc hl, de - ret nz - inc a - ret - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/eq32.asm b/src/lib/arch/zxnext/runtime/cmp/eq32.asm index fb51892bd..a345f1dc9 100644 --- a/src/lib/arch/zxnext/runtime/cmp/eq32.asm +++ b/src/lib/arch/zxnext/runtime/cmp/eq32.asm @@ -1,29 +1,8 @@ - push namespace core - -__EQ32: ; Test if 32bit value HLDE equals top of the stack - ; Returns result in A: 0 = False, FF = True - exx - pop bc ; Return address - exx - - xor a ; Reset carry flag - pop bc - sbc hl, bc ; Low part - ex de, hl - pop bc - sbc hl, bc ; High part - - exx - push bc ; CALLEE - exx - - ld a, h - or l - or d - or e ; a = 0 and Z flag set only if HLDE = 0 - ld a, 1 - ret z - xor a - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/eqf.asm b/src/lib/arch/zxnext/runtime/cmp/eqf.asm index a2dd56e3e..29d2e58d7 100644 --- a/src/lib/arch/zxnext/runtime/cmp/eqf.asm +++ b/src/lib/arch/zxnext/runtime/cmp/eqf.asm @@ -1,30 +1,8 @@ -#include once -#include once -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses C EDHL registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order BC DE HL (B not used). +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Uses CALLEE convention -; ------------------------------------------------------------- - - - push namespace core - -__EQF: ; A = B - call __FPSTACK_PUSH2 - - ; ------------- ROM NOS-EQL - ld b, 0Eh ; For comparison operators, OP must be in B also - rst 28h - defb 0Eh - defb 38h; ; END CALC - - call __FPSTACK_POP - jp __FTOU8 ; Convert to 8 bits +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/gef.asm b/src/lib/arch/zxnext/runtime/cmp/gef.asm index af52e8dc0..3d5743351 100644 --- a/src/lib/arch/zxnext/runtime/cmp/gef.asm +++ b/src/lib/arch/zxnext/runtime/cmp/gef.asm @@ -1,30 +1,8 @@ -#include once -#include once -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses A EDCB registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order A DE BC. +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Uses CALLEE convention -; ------------------------------------------------------------- - - - push namespace core - -__GEF: ; A >= B - call __FPSTACK_PUSH2 ; Enters B, A - - ; ------------- ROM NO-LESS - ld b, 09h ; B =< A - rst 28h - defb 09h - defb 38h ; END CALC - - call __FPSTACK_POP - jp __FTOU8 ; Convert to 8 bits +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/gtf.asm b/src/lib/arch/zxnext/runtime/cmp/gtf.asm index 637887cff..6c91c3e51 100644 --- a/src/lib/arch/zxnext/runtime/cmp/gtf.asm +++ b/src/lib/arch/zxnext/runtime/cmp/gtf.asm @@ -1,29 +1,8 @@ -#include once -#include once -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses A EDCB registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order A DE BC. +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Uses CALLEE convention -; ------------------------------------------------------------- - - push namespace core - -__GTF: ; A > B - call __FPSTACK_PUSH2 ; ENTERS B, A - - ; ------------- ROM NOS-GRTR - ld b, 0Dh ; B < A - rst 28h - defb 0Dh ; B < A - defb 38h; ; END CALC - - call __FPSTACK_POP - jp __FTOU8; Convert to 8 bits +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/lef.asm b/src/lib/arch/zxnext/runtime/cmp/lef.asm index e5a67b6a8..c245a6158 100644 --- a/src/lib/arch/zxnext/runtime/cmp/lef.asm +++ b/src/lib/arch/zxnext/runtime/cmp/lef.asm @@ -1,29 +1,8 @@ -#include once -#include once -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses A EDCB registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order A DE BC. +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Uses CALLEE convention -; ------------------------------------------------------------- - - push namespace core - -__LEF: ; A <= B - call __FPSTACK_PUSH2 ; B, A - - ; ------------- ROM NO-L-EQL - ld b, 0Ah ; B => A - rst 28h - defb 0Ah ; B => A - defb 38h; ; END CALC - - call __FPSTACK_POP - jp __FTOU8 ; Convert to 8 bits +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/lei16.asm b/src/lib/arch/zxnext/runtime/cmp/lei16.asm index 60d5cb65a..6f07c8a1f 100644 --- a/src/lib/arch/zxnext/runtime/cmp/lei16.asm +++ b/src/lib/arch/zxnext/runtime/cmp/lei16.asm @@ -1,20 +1,8 @@ - push namespace core +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -__LEI16: - PROC - LOCAL checkParity - or a - sbc hl, de - ld a, 1 - ret z - jp po, checkParity - ld a, h - xor 0x80 -checkParity: - ld a, 0 ; False - ret p - inc a ; True - ret - ENDP - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/lei32.asm b/src/lib/arch/zxnext/runtime/cmp/lei32.asm index c79c094b6..209e3dee8 100644 --- a/src/lib/arch/zxnext/runtime/cmp/lei32.asm +++ b/src/lib/arch/zxnext/runtime/cmp/lei32.asm @@ -1,38 +1,8 @@ - -#include once - - push namespace core - -__LEI32: ; Test 32 bit values Top of the stack <= HL,DE - PROC - LOCAL checkParity - exx - pop de ; Preserves return address - exx - - call __SUB32 - - exx - push de ; Puts return address back - exx - - ex af, af' - ld a, h - or l - or e - or d - ld a, 1 - ret z - - ex af, af' - jp po, checkParity - ld a, d - xor 0x80 -checkParity: - ld a, 0 ; False - ret p - inc a ; True - ret - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/lei8.asm b/src/lib/arch/zxnext/runtime/cmp/lei8.asm index 6480a963b..599e68763 100644 --- a/src/lib/arch/zxnext/runtime/cmp/lei8.asm +++ b/src/lib/arch/zxnext/runtime/cmp/lei8.asm @@ -1,25 +1,8 @@ - push namespace core - -__LEI8: ; Signed <= comparison for 8bit int - ; A <= H (registers) - PROC - LOCAL checkParity - sub h - jr nz, __LTI - inc a - ret - -__LTI8: ; Test 8 bit values A < H - sub h - -__LTI: ; Generic signed comparison - jp po, checkParity - xor 0x80 -checkParity: - ld a, 0 ; False - ret p - inc a ; True - ret - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/ltf.asm b/src/lib/arch/zxnext/runtime/cmp/ltf.asm index f6be6d29e..bbfa4e933 100644 --- a/src/lib/arch/zxnext/runtime/cmp/ltf.asm +++ b/src/lib/arch/zxnext/runtime/cmp/ltf.asm @@ -1,29 +1,8 @@ -#include once -#include once -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses A EDCB registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order A HL BC. +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Uses CALLEE convention -; ------------------------------------------------------------- - - push namespace core - -__LTF: ; A < B - call __FPSTACK_PUSH2 ; Enters B, A - - ; ------------- ROM NOS-LESS - ld b, 0Ch ; A > B (Operands stack-reversed) - rst 28h - defb 0Ch; ; A > B - defb 38h; ; END CALC - - call __FPSTACK_POP - jp __FTOU8 ; Convert to 8 bits +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/lti16.asm b/src/lib/arch/zxnext/runtime/cmp/lti16.asm index b59f8fba6..e9012b683 100644 --- a/src/lib/arch/zxnext/runtime/cmp/lti16.asm +++ b/src/lib/arch/zxnext/runtime/cmp/lti16.asm @@ -1,21 +1,8 @@ -#include once +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - push namespace core - -__LTI16: ; Test 8 bit values HL < DE - ; Returns result in A: 0 = False, !0 = True - PROC - LOCAL checkParity - or a - sbc hl, de - jp po, checkParity - ld a, h - xor 0x80 -checkParity: - ld a, 0 ; False - ret p - inc a ; True - ret - ENDP - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/lti32.asm b/src/lib/arch/zxnext/runtime/cmp/lti32.asm index 2f3e100a4..07ace187a 100644 --- a/src/lib/arch/zxnext/runtime/cmp/lti32.asm +++ b/src/lib/arch/zxnext/runtime/cmp/lti32.asm @@ -1,29 +1,8 @@ - -#include once - - push namespace core - -__LTI32: ; Test 32 bit values in Top of the stack < HLDE - PROC - LOCAL checkParity - exx - pop de ; Preserves return address - exx - - call __SUB32 - - exx - push de ; Restores return address - exx - - jp po, checkParity - ld a, d - xor 0x80 -checkParity: - ld a, 0 ; False - ret p - inc a ; True - ret - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/lti8.asm b/src/lib/arch/zxnext/runtime/cmp/lti8.asm index 9a8ac8ced..29b117e71 100644 --- a/src/lib/arch/zxnext/runtime/cmp/lti8.asm +++ b/src/lib/arch/zxnext/runtime/cmp/lti8.asm @@ -1 +1,8 @@ -#include once +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/cmp/nef.asm b/src/lib/arch/zxnext/runtime/cmp/nef.asm index 94cea1b02..6990e1ffc 100644 --- a/src/lib/arch/zxnext/runtime/cmp/nef.asm +++ b/src/lib/arch/zxnext/runtime/cmp/nef.asm @@ -1,29 +1,8 @@ -#include once -#include once -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses A EDCB registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order A DE BC. +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Uses CALLEE convention -; ------------------------------------------------------------- - - push namespace core - -__NEF: ; A <> B - call __FPSTACK_PUSH2 ; Enters B, A - - ; ------------- ROM NOS-NEQ - ld b, 0Bh - rst 28h - defb 0Bh - defb 38h ; END CALC - - call __FPSTACK_POP - jp __FTOU8 ; Convert to 8 bits +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/copy_attr.asm b/src/lib/arch/zxnext/runtime/copy_attr.asm index 15015ec18..9a31de189 100644 --- a/src/lib/arch/zxnext/runtime/copy_attr.asm +++ b/src/lib/arch/zxnext/runtime/copy_attr.asm @@ -1,80 +1,8 @@ -#ifdef ___PRINT_IS_USED___ -#include once -#endif - -#include once - - push namespace core - -COPY_ATTR: - ; Just copies current permanent attribs into temporal attribs - ; and sets print mode - PROC - - LOCAL INVERSE1 - LOCAL __REFRESH_TMP - -INVERSE1 EQU 02Fh - - ld hl, (ATTR_P) - ld (ATTR_T), hl - - ld hl, FLAGS2 - call __REFRESH_TMP - - ld hl, P_FLAG - call __REFRESH_TMP - - -__SET_ATTR_MODE: ; Another entry to set print modes. A contains (P_FLAG) - -#ifdef ___PRINT_IS_USED___ - LOCAL TABLE - LOCAL CONT2 - - rra ; Over bit to carry - ld a, (FLAGS2) - rla ; Over bit in bit 1, Over2 bit in bit 2 - and 3 ; Only bit 0 and 1 (OVER flag) - - ld c, a - ld b, 0 - - ld hl, TABLE - add hl, bc - ld a, (hl) - ld (PRINT_MODE), a - - ld hl, (P_FLAG) - xor a ; NOP -> INVERSE0 - bit 2, l - jr z, CONT2 - ld a, INVERSE1 ; CPL -> INVERSE1 - -CONT2: - ld (INVERSE_MODE), a - ret - -TABLE: - nop ; NORMAL MODE - xor (hl) ; OVER 1 MODE - and (hl) ; OVER 2 MODE - or (hl) ; OVER 3 MODE - -#else - ret -#endif - -__REFRESH_TMP: - ld a, (hl) - and 0b10101010 - ld c, a - rra - or c - ld (hl), a - ret - - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/draw.asm b/src/lib/arch/zxnext/runtime/draw.asm index aea5b49a1..8880ffd1c 100644 --- a/src/lib/arch/zxnext/runtime/draw.asm +++ b/src/lib/arch/zxnext/runtime/draw.asm @@ -1,336 +1,8 @@ -; DRAW using bresenhams algorithm and screen positioning -; Copyleft (k) 2010 by J. Rodriguez (a.k.a. Boriel) http://www.boriel.com -; vim:ts=4:et:sw=4: - -; Y parameter in A -; X parameter in high byte on top of the stack - -#include once -#include once - -#include once -#include once - -#include once -#include once -#include once -#include once - -;; DRAW PROCEDURE - push namespace core - - PROC - - LOCAL __DRAW1 - LOCAL __DRAW2 - LOCAL __DRAW3 - LOCAL __DRAW4, __DRAW4_LOOP - LOCAL __DRAW5 - LOCAL __DRAW6, __DRAW6_LOOP - LOCAL __DRAW_ERROR - LOCAL DX1, DX2, DY1, DY2 - LOCAL __INCX, __INCY, __DECX, __DECY - LOCAL P_FLAG -P_FLAG EQU 23697 - -__DRAW_ERROR: - jp __OUT_OF_SCREEN_ERR - -DRAW: - ;; ENTRY POINT - - LOCAL COORDS - LOCAL __DRAW_SETUP1, __DRAW_START, __PLOTOVER, __PLOTINVERSE - - ex de, hl ; DE = Y OFFSET - pop hl ; return addr - ex (sp), hl ; CALLEE => HL = X OFFSET - ld bc, (COORDS) - - ld a, c - add a, l - ld l, a - ld a, h - adc a, 0 ; HL = HL + C - ld h, a - jr nz, __DRAW_ERROR ; if a <> 0 => Out of Screen - - ld a, b - add a, e - ld e, a - ld a, d - adc a, 0 ; DE = DE + B - ld d, a - jr nz, __DRAW_ERROR ; if a <> 0 => Out of Screen - - ld a, 191 - sub e - jr c, __DRAW_ERROR ; Out of screen - - ld h, e ; now H,L = y2, x2 - -__DRAW: - ; __FASTCALL__ Entry. Plots from (COORDS) to coord H, L - push hl - ex de, hl ; D,E = y2, x2; - - ld a, (P_FLAG) - ld c, a - bit 2, a ; Test for INVERSE1 - jr z, __DRAW_SETUP1 - ld a, 2Fh ; CPL - ld (__PLOTINVERSE), a - ld a, 0A6h ; and (hl) - jp __DRAW_START - -__DRAW_SETUP1: - xor a ; nop - ld (__PLOTINVERSE), a - ld a, 0B6h ; or (hl) - bit 0, c ; Test for OVER - jr z, __DRAW_START - ld a, 0AEh ; xor (hl) - -__DRAW_START: - ld (__PLOTOVER), a ; "Pokes" last operation - exx - ld bc, (COORDS) ; B'C' = y1, x1 - ld d, b ; Saves B' in D' - ld a, 191 - LOCAL __PIXEL_ADDR -__PIXEL_ADDR EQU 22ACh - call __PIXEL_ADDR - res 6, h ; Starts from 0 offset - - ;; Now gets pixel mask in A register - ld b, a - inc b - xor a - scf - LOCAL __PIXEL_MASK -__PIXEL_MASK: - rra - djnz __PIXEL_MASK - - ld b, d ; Restores B' from D' - ld de, (SCREEN_ADDR) - add hl, de - pop de ; D'E' = y2, x2 - exx ; At this point: D'E' = y2,x2 coords - ; B'C' = y1, y1 coords - ; H'L' = Screen Address of pixel - - ex af, af' ; Saves A reg for later - ; A' = Pixel mask - - ld bc, (COORDS) ; B,C = y1, x1 - - ld a, e - sub c ; dx = X2 - X1 - ld c, a ; Saves dx in c - - ld a, 0Ch ; INC C opcode - ld hl, __INCX ; xi = 1 - jr nc, __DRAW1 - - ld a, c - neg ; dx = X1 - X2 - ld c, a - ld a, 0Dh ; DEC C opcode - ld hl, __DECX ; xi = -1 - -__DRAW1: - ld (DX1), a - ld (DX1 + 2), hl ; Updates DX1 call address - ld (DX2), a - ld (DX2 + 2), hl ; Updates DX2 call address - - ld a, d - sub b ; dy = Y2 - Y1 - ld b, a ; Saves dy in b - - ld a, 4 ; INC B opcode - ld hl, __INCY ; y1 = 1 - jr nc, __DRAW2 - - ld a, b - neg - ld b, a ; dy = Y2 - Y1 - ld a, 5 ; DEC B opcode - ld hl, __DECY ; y1 = -1 - -__DRAW2: - ld (DY1), a - ld (DY1 + 2), hl ; Updates DX1 call address - ld (DY2), a - ld (DY2 + 2), hl ; Updates DX2 call address - - ld a, b - sub c ; dy - dx - jr c, __DRAW_DX_GT_DY ; DX > DY - - ; At this point DY >= DX - ; -------------------------- - ; HL = error = dY / 2 - ld h, 0 - ld l, b - srl l - - ; DE = -dX - xor a - sub c - ld e, a - sbc a, a - ld d, a - - ; BC = DY - ld c, b - ld b, h - - exx - scf ; Sets Carry to signal update ATTR - ex af, af' ; Brings back pixel mask - ld e, a ; Saves it in free E register - jp __DRAW4_LOOP - -__DRAW3: ; While c != e => while y != y2 - exx - add hl, de ; error -= dX - bit 7, h ; - exx ; recover coordinates - jr z, __DRAW4 ; if error < 0 - - exx - add hl, bc ; error += dY - exx - - ld a, e -DX1: ; x += xi - inc c - call __INCX ; This address will be dynamically updated - ld e, a - -__DRAW4: - -DY1: ; y += yi - inc b - call __INCY ; This address will be dynamically updated - ld a, e ; Restores A reg. - call __FASTPLOT - -__DRAW4_LOOP: - ld a, b - cp d - jp nz, __DRAW3 - ld (COORDS), bc - ret - -__DRAW_DX_GT_DY: ; DX > DY - ; -------------------------- - ; HL = error = dX / 2 - ld h, 0 - ld l, c - srl l ; HL = error = DX / 2 - - ; DE = -dY - xor a - sub b - ld e, a - sbc a, a - ld d, a - - ; BC = dX - ld b, h - - exx - ld d, e - scf ; Sets Carry to signal update ATTR - ex af, af' ; Brings back pixel mask - ld e, a ; Saves it in free E register - jp __DRAW6_LOOP - -__DRAW5: ; While loop - exx - add hl, de ; error -= dY - bit 7, h ; if (error < 0) - exx ; Restore coords - jr z, __DRAW6 ; - exx - add hl, bc ; error += dX - exx - -DY2: ; y += yi - inc b - call __INCY ; This address will be dynamically updated - -__DRAW6: - ld a, e -DX2: ; x += xi - inc c - call __INCX ; This address will be dynamically updated - ld e, a - call __FASTPLOT - -__DRAW6_LOOP: - ld a, c ; Current X coord - cp d - jp nz, __DRAW5 - ld (COORDS), bc - ret - -COORDS EQU 5C7Dh - -__DRAW_END: - exx - ret - - ;; Given a A mask and an HL screen position - ;; return the next left position - ;; Also updates BC coords -__DECX EQU SP.PixelLeft - - ;; Like the above, but to the RIGHT - ;; Also updates BC coords -__INCX EQU SP.PixelRight - - ;; Given an HL screen position, calculates - ;; the above position - ;; Also updates BC coords -__INCY EQU SP.PixelUp - - ;; Given an HL screen position, calculates - ;; the above position - ;; Also updates BC coords -__DECY EQU SP.PixelDown - - ;; Puts the A register MASK in (HL) -__FASTPLOT: -__PLOTINVERSE: - nop ; Replace with CPL if INVERSE 1 -__PLOTOVER: - or (hl) ; Replace with XOR (hl) if OVER 1 AND INVERSE 0 - ; Replace with AND (hl) if INVERSE 1 - - ld (hl), a - ex af, af' ; Recovers flag. If Carry set => update ATTR - ld a, e ; Recovers A reg - ret nc - - push hl - push de - push bc - call SET_PIXEL_ADDR_ATTR - pop bc - pop de - pop hl - - LOCAL __FASTPLOTEND -__FASTPLOTEND: - or a ; Resets carry flag - ex af, af' ; Recovers A reg - ld a, e - ret - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/draw3.asm b/src/lib/arch/zxnext/runtime/draw3.asm index 956acffb8..eb67eff3d 100644 --- a/src/lib/arch/zxnext/runtime/draw3.asm +++ b/src/lib/arch/zxnext/runtime/draw3.asm @@ -1,511 +1,8 @@ -; ----------------------------------------------------------- -; vim: et:ts=4:sw=4:ruler: +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; DRAW an arc using ZX ROM algorithm. -; DRAW x, y, r => r = Arc in radians +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -; r parameter in A ED BC register -; X, and Y parameter in high byte on top of the stack - -#include once -#include once -#include once -#include once -#include once - -; Ripped from the ZX Spectrum ROM - - push namespace core - -DRAW3: - PROC - LOCAL STACK_TO_BC - LOCAL STACK_TO_A - LOCAL L2477 - LOCAL L2420 - LOCAL L2439 - LOCAL L245F - LOCAL L23C1 - LOCAL L2D28 - LOCAL SUM_C, SUM_B - -L2D28 EQU 02D28h -STACK_TO_BC EQU 2307h -STACK_TO_A EQU 2314h - - exx - ex af, af' ;; Preserves ARC - pop hl - pop de - ex (sp), hl ;; CALLEE - push de - call __FPSTACK_I16 ;; X Offset - pop hl - call __FPSTACK_I16 ;; Y Offset - exx - ex af, af' - call __FPSTACK_PUSH ;; R Arc - -; Now enter the calculator and store the complete rotation angle in mem-5 - - RST 28H ;; FP-CALC x, y, A. - DEFB $C5 ;;st-mem-5 x, y, A. - -; Test the angle for the special case of 360 degrees. - - DEFB $A2 ;;stk-half x, y, A, 1/2. - DEFB $04 ;;multiply x, y, A/2. - DEFB $1F ;;sin x, y, sin(A/2). - DEFB $31 ;;duplicate x, y, sin(A/2),sin(A/2) - DEFB $30 ;;not x, y, sin(A/2), (0/1). - DEFB $30 ;;not x, y, sin(A/2), (1/0). - DEFB $00 ;;jump-true x, y, sin(A/2). - - DEFB $06 ;;forward to L23A3, DR-SIN-NZ - ;;if sin(r/2) is not zero. - -; The third parameter is 2*PI (or a multiple of 2*PI) so a 360 degrees turn -; would just be a straight line. Eliminating this case here prevents -; division by zero at later stage. - - DEFB $02 ;;delete x, y. - DEFB $38 ;;end-calc x, y. - JP L2477 - -; --- - -; An arc can be drawn. - -;; DR-SIN-NZ - DEFB $C0 ;;st-mem-0 x, y, sin(A/2). store mem-0 - DEFB $02 ;;delete x, y. - -; The next step calculates (roughly) the diameter of the circle of which the -; arc will form part. This value does not have to be too accurate as it is -; only used to evaluate the number of straight lines and then discarded. -; After all for a circle, the radius is used. Consequently, a circle of -; radius 50 will have 24 straight lines but an arc of radius 50 will have 20 -; straight lines - when drawn in any direction. -; So that simple arithmetic can be used, the length of the chord can be -; calculated as X+Y rather than by Pythagoras Theorem and the sine of the -; nearest angle within reach is used. - - DEFB $C1 ;;st-mem-1 x, y. store mem-1 - DEFB $02 ;;delete x. - - DEFB $31 ;;duplicate x, x. - DEFB $2A ;;abs x, x (+ve). - DEFB $E1 ;;get-mem-1 x, X, y. - DEFB $01 ;;exchange x, y, X. - DEFB $E1 ;;get-mem-1 x, y, X, y. - DEFB $2A ;;abs x, y, X, Y (+ve). - DEFB $0F ;;addition x, y, X+Y. - DEFB $E0 ;;get-mem-0 x, y, X+Y, sin(A/2). - DEFB $05 ;;division x, y, X+Y/sin(A/2). - DEFB $2A ;;abs x, y, X+Y/sin(A/2) = D. - -; Bring back sin(A/2) from mem-0 which will shortly get trashed. -; Then bring D to the top of the stack again. - - DEFB $E0 ;;get-mem-0 x, y, D, sin(A/2). - DEFB $01 ;;exchange x, y, sin(A/2), D. - -; Note. that since the value at the top of the stack has arisen as a result -; of division then it can no longer be in integer form and the next re-stack -; is unnecessary. Only the Sinclair ZX80 had integer division. - - ;;DEFB $3D ;;re-stack (unnecessary) - - DEFB $38 ;;end-calc x, y, sin(A/2), D. - -; The next test avoids drawing 4 straight lines when the start and end pixels -; are adjacent (or the same) but is probably best dispensed with. - - LD A,(HL) ; fetch exponent byte of D. - CP $81 ; compare to 1 - JR NC,L23C1 ; forward, if > 1, to DR-PRMS - -; else delete the top two stack values and draw a simple straight line. - - RST 28H ;; FP-CALC - DEFB $02 ;;delete - DEFB $02 ;;delete - DEFB $38 ;;end-calc x, y. - - JP L2477 ; to LINE-DRAW - -; --- - -; The ARC will consist of multiple straight lines so call the CIRCLE-DRAW -; PARAMETERS ROUTINE to pre-calculate sine values from the angle (in mem-5) -; and determine also the number of straight lines from that value and the -; 'diameter' which is at the top of the calculator stack. - -;; DR-PRMS -L23C1: CALL 247Dh ; routine CD-PRMS1 - - ; mem-0 ; (A)/No. of lines (=a) (step angle) - ; mem-1 ; sin(a/2) - ; mem-2 ; - - ; mem-3 ; cos(a) const - ; mem-4 ; sin(a) const - ; mem-5 ; Angle of rotation (A) in - ; B ; Count of straight lines - max 252. - - PUSH BC ; Save the line count on the machine stack. - -; Remove the now redundant diameter value D. - - RST 28H ;; FP-CALC x, y, sin(A/2), D. - DEFB $02 ;;delete x, y, sin(A/2). - -; Dividing the sine of the step angle by the sine of the total angle gives -; the length of the initial chord on a unary circle. This factor f is used -; to scale the coordinates of the first line which still points in the -; direction of the end point and may be larger. - - DEFB $E1 ;;get-mem-1 x, y, sin(A/2), sin(a/2) - DEFB $01 ;;exchange x, y, sin(a/2), sin(A/2) - DEFB $05 ;;division x, y, sin(a/2)/sin(A/2) - DEFB $C1 ;;st-mem-1 x, y. f. - DEFB $02 ;;delete x, y. - -; With the factor stored, scale the x coordinate first. - - DEFB $01 ;;exchange y, x. - DEFB $31 ;;duplicate y, x, x. - DEFB $E1 ;;get-mem-1 y, x, x, f. - DEFB $04 ;;multiply y, x, x*f (=xx) - DEFB $C2 ;;st-mem-2 y, x, xx. - DEFB $02 ;;delete y. x. - -; Now scale the y coordinate. - - DEFB $01 ;;exchange x, y. - DEFB $31 ;;duplicate x, y, y. - DEFB $E1 ;;get-mem-1 x, y, y, f - DEFB $04 ;;multiply x, y, y*f (=yy) - -; Note. 'sin' and 'cos' trash locations mem-0 to mem-2 so fetch mem-2 to the -; calculator stack for safe keeping. - - DEFB $E2 ;;get-mem-2 x, y, yy, xx. - -; Once we get the coordinates of the first straight line then the 'ROTATION -; FORMULA' used in the arc loop will take care of all other points, but we -; now use a variation of that formula to rotate the first arc through (A-a)/2 -; radians. -; -; xRotated = y * sin(angle) + x * cos(angle) -; yRotated = y * cos(angle) - x * sin(angle) -; - - DEFB $E5 ;;get-mem-5 x, y, yy, xx, A. - DEFB $E0 ;;get-mem-0 x, y, yy, xx, A, a. - DEFB $03 ;;subtract x, y, yy, xx, A-a. - DEFB $A2 ;;stk-half x, y, yy, xx, A-a, 1/2. - DEFB $04 ;;multiply x, y, yy, xx, (A-a)/2. (=angle) - DEFB $31 ;;duplicate x, y, yy, xx, angle, angle. - DEFB $1F ;;sin x, y, yy, xx, angle, sin(angle) - DEFB $C5 ;;st-mem-5 x, y, yy, xx, angle, sin(angle) - DEFB $02 ;;delete x, y, yy, xx, angle - - DEFB $20 ;;cos x, y, yy, xx, cos(angle). - -; Note. mem-0, mem-1 and mem-2 can be used again now... - - DEFB $C0 ;;st-mem-0 x, y, yy, xx, cos(angle). - DEFB $02 ;;delete x, y, yy, xx. - - DEFB $C2 ;;st-mem-2 x, y, yy, xx. - DEFB $02 ;;delete x, y, yy. - - DEFB $C1 ;;st-mem-1 x, y, yy. - DEFB $E5 ;;get-mem-5 x, y, yy, sin(angle) - DEFB $04 ;;multiply x, y, yy*sin(angle). - DEFB $E0 ;;get-mem-0 x, y, yy*sin(angle), cos(angle) - DEFB $E2 ;;get-mem-2 x, y, yy*sin(angle), cos(angle), xx. - DEFB $04 ;;multiply x, y, yy*sin(angle), xx*cos(angle). - DEFB $0F ;;addition x, y, xRotated. - DEFB $E1 ;;get-mem-1 x, y, xRotated, yy. - DEFB $01 ;;exchange x, y, yy, xRotated. - DEFB $C1 ;;st-mem-1 x, y, yy, xRotated. - DEFB $02 ;;delete x, y, yy. - - DEFB $E0 ;;get-mem-0 x, y, yy, cos(angle). - DEFB $04 ;;multiply x, y, yy*cos(angle). - DEFB $E2 ;;get-mem-2 x, y, yy*cos(angle), xx. - DEFB $E5 ;;get-mem-5 x, y, yy*cos(angle), xx, sin(angle). - DEFB $04 ;;multiply x, y, yy*cos(angle), xx*sin(angle). - DEFB $03 ;;subtract x, y, yRotated. - DEFB $C2 ;;st-mem-2 x, y, yRotated. - -; Now the initial x and y coordinates are made positive and summed to see -; if they measure up to anything significant. - - DEFB $2A ;;abs x, y, yRotated'. - DEFB $E1 ;;get-mem-1 x, y, yRotated', xRotated. - DEFB $2A ;;abs x, y, yRotated', xRotated'. - DEFB $0F ;;addition x, y, yRotated+xRotated. - DEFB $02 ;;delete x, y. - - DEFB $38 ;;end-calc x, y. - -; Although the test value has been deleted it is still above the calculator -; stack in memory and conveniently DE which points to the first free byte -; addresses the exponent of the test value. - - LD A,(DE) ; Fetch exponent of the length indicator. - CP $81 ; Compare to that for 1 - - POP BC ; Balance the machine stack - - JP C,L2477 ; forward, if the coordinates of first line - ; don't add up to more than 1, to LINE-DRAW - -; Continue when the arc will have a discernable shape. - - PUSH BC ; Restore line counter to the machine stack. - -; The parameters of the DRAW command were relative and they are now converted -; to absolute coordinates by adding to the coordinates of the last point -; plotted. The first two values on the stack are the terminal tx and ty -; coordinates. The x-coordinate is converted first but first the last point -; plotted is saved as it will initialize the moving ax, value. - - RST 28H ;; FP-CALC x, y. - DEFB $01 ;;exchange y, x. - DEFB $38 ;;end-calc y, x. - - LD A,(COORDS) ;; Fetch System Variable COORDS-x - CALL L2D28 ;; routine STACK-A - - RST 28H ;; FP-CALC y, x, last-x. - -; Store the last point plotted to initialize the moving ax value. - - DEFB $C0 ;;st-mem-0 y, x, last-x. - DEFB $0F ;;addition y, absolute x. - DEFB $01 ;;exchange tx, y. - DEFB $38 ;;end-calc tx, y. - - LD A,(COORDS + 1) ; Fetch System Variable COORDS-y - CALL L2D28 ; routine STACK-A - - RST 28H ;; FP-CALC tx, y, last-y. - -; Store the last point plotted to initialize the moving ay value. - - DEFB $C5 ;;st-mem-5 tx, y, last-y. - DEFB $0F ;;addition tx, ty. - -; Fetch the moving ax and ay to the calculator stack. - - DEFB $E0 ;;get-mem-0 tx, ty, ax. - DEFB $E5 ;;get-mem-5 tx, ty, ax, ay. - DEFB $38 ;;end-calc tx, ty, ax, ay. - - POP BC ; Restore the straight line count. - -; ----------------------------------- -; THE 'CIRCLE/DRAW CONVERGENCE POINT' -; ----------------------------------- -; The CIRCLE and ARC-DRAW commands converge here. -; -; Note. for both the CIRCLE and ARC commands the minimum initial line count -; is 4 (as set up by the CD_PARAMS routine) and so the zero flag will never -; be set and the loop is always entered. The first test is superfluous and -; the jump will always be made to ARC-START. - -;; DRW-STEPS -L2420: - DEC B ; decrement the arc count (4,8,12,16...). - - ;JR Z,L245F ; forward, if zero (not possible), to ARC-END - - JP L2439 ; forward to ARC-START - -; -------------- -; THE 'ARC LOOP' -; -------------- -; -; The arc drawing loop will draw up to 31 straight lines for a circle and up -; 251 straight lines for an arc between two points. In both cases the final -; closing straight line is drawn at ARC_END, but it otherwise loops back to -; here to calculate the next coordinate using the ROTATION FORMULA where (a) -; is the previously calculated, constant CENTRAL ANGLE of the arcs. -; -; Xrotated = x * cos(a) - y * sin(a) -; Yrotated = x * sin(a) + y * cos(a) -; -; The values cos(a) and sin(a) are pre-calculated and held in mem-3 and mem-4 -; for the duration of the routine. -; Memory location mem-1 holds the last relative x value (rx) and mem-2 holds -; the last relative y value (ry) used by DRAW. -; -; Note. that this is a very clever twist on what is after all a very clever, -; well-used formula. Normally the rotation formula is used with the x and y -; coordinates from the centre of the circle (or arc) and a supplied angle to -; produce two new x and y coordinates in an anticlockwise direction on the -; circumference of the circle. -; What is being used here, instead, is the relative X and Y parameters from -; the last point plotted that are required to get to the current point and -; the formula returns the next relative coordinates to use. - -;; ARC-LOOP -L2425: - RST 28H ;; FP-CALC - DEFB $E1 ;;get-mem-1 rx. - DEFB $31 ;;duplicate rx, rx. - DEFB $E3 ;;get-mem-3 cos(a) - DEFB $04 ;;multiply rx, rx*cos(a). - DEFB $E2 ;;get-mem-2 rx, rx*cos(a), ry. - DEFB $E4 ;;get-mem-4 rx, rx*cos(a), ry, sin(a). - DEFB $04 ;;multiply rx, rx*cos(a), ry*sin(a). - DEFB $03 ;;subtract rx, rx*cos(a) - ry*sin(a) - DEFB $C1 ;;st-mem-1 rx, new relative x rotated. - DEFB $02 ;;delete rx. - - DEFB $E4 ;;get-mem-4 rx, sin(a). - DEFB $04 ;;multiply rx*sin(a) - DEFB $E2 ;;get-mem-2 rx*sin(a), ry. - DEFB $E3 ;;get-mem-3 rx*sin(a), ry, cos(a). - DEFB $04 ;;multiply rx*sin(a), ry*cos(a). - DEFB $0F ;;addition rx*sin(a) + ry*cos(a). - DEFB $C2 ;;st-mem-2 new relative y rotated. - DEFB $02 ;;delete . - DEFB $38 ;;end-calc . - -; Note. the calculator stack actually holds tx, ty, ax, ay -; and the last absolute values of x and y -; are now brought into play. -; -; Magically, the two new rotated coordinates rx and ry are all that we would -; require to draw a circle or arc - on paper! -; The Spectrum DRAW routine draws to the rounded x and y coordinate and so -; repetitions of values like 3.49 would mean that the fractional parts -; would be lost until eventually the draw coordinates might differ from the -; floating point values used above by several pixels. -; For this reason the accurate offsets calculated above are added to the -; accurate, absolute coordinates maintained in ax and ay and these new -; coordinates have the integer coordinates of the last plot position -; ( from System Variable COORDS ) subtracted from them to give the relative -; coordinates required by the DRAW routine. - -; The mid entry point. - -;; ARC-START -L2439: - PUSH BC ; Preserve the arc counter on the machine stack. - -; Store the absolute ay in temporary variable mem-0 for the moment. - - RST 28H ;; FP-CALC ax, ay. - DEFB $C0 ;;st-mem-0 ax, ay. - DEFB $02 ;;delete ax. - -; Now add the fractional relative x coordinate to the fractional absolute -; x coordinate to obtain a new fractional x-coordinate. - - DEFB $E1 ;;get-mem-1 ax, xr. - DEFB $0F ;;addition ax+xr (= new ax). - DEFB $31 ;;duplicate ax, ax. - DEFB $38 ;;end-calc ax, ax. - - LD A,(COORDS) ; COORDS-x last x (integer ix 0-255) - CALL L2D28 ; routine STACK-A - - RST 28H ;; FP-CALC ax, ax, ix. - DEFB $03 ;;subtract ax, ax-ix = relative DRAW Dx. - -; Having calculated the x value for DRAW do the same for the y value. - - DEFB $E0 ;;get-mem-0 ax, Dx, ay. - DEFB $E2 ;;get-mem-2 ax, Dx, ay, ry. - DEFB $0F ;;addition ax, Dx, ay+ry (= new ay). - DEFB $C0 ;;st-mem-0 ax, Dx, ay. - DEFB $01 ;;exchange ax, ay, Dx, - DEFB $E0 ;;get-mem-0 ax, ay, Dx, ay. - DEFB $38 ;;end-calc ax, ay, Dx, ay. - - LD A,(COORDS + 1) ; COORDS-y last y (integer iy 0-175) - CALL L2D28 ; routine STACK-A - - RST 28H ;; FP-CALC ax, ay, Dx, ay, iy. - DEFB $03 ;;subtract ax, ay, Dx, ay-iy ( = Dy). - DEFB $38 ;;end-calc ax, ay, Dx, Dy. - - CALL L2477 ; Routine DRAW-LINE draws (Dx,Dy) relative to - ; the last pixel plotted leaving absolute x - ; and y on the calculator stack. - ; ax, ay. - - POP BC ; Restore the arc counter from the machine stack. - - DJNZ L2425 ; Decrement and loop while > 0 to ARC-LOOP - -; ------------- -; THE 'ARC END' -; ------------- - -; To recap the full calculator stack is tx, ty, ax, ay. - -; Just as one would do if drawing the curve on paper, the final line would -; be drawn by joining the last point plotted to the initial start point -; in the case of a CIRCLE or to the calculated end point in the case of -; an ARC. -; The moving absolute values of x and y are no longer required and they -; can be deleted to expose the closing coordinates. - -;; ARC-END -L245F: - RST 28H ;; FP-CALC tx, ty, ax, ay. - DEFB $02 ;;delete tx, ty, ax. - DEFB $02 ;;delete tx, ty. - DEFB $01 ;;exchange ty, tx. - DEFB $38 ;;end-calc ty, tx. - -; First calculate the relative x coordinate to the end-point. - - LD A,(COORDS) ; COORDS-x - CALL L2D28 ; routine STACK-A - - RST 28H ;; FP-CALC ty, tx, coords_x. - DEFB $03 ;;subtract ty, rx. - -; Next calculate the relative y coordinate to the end-point. - - DEFB $01 ;;exchange rx, ty. - DEFB $38 ;;end-calc rx, ty. - - LD A,(COORDS + 1) ; COORDS-y - CALL L2D28 ; routine STACK-A - - RST 28H ;; FP-CALC rx, ty, coords_y - DEFB $03 ;;subtract rx, ry. - DEFB $38 ;;end-calc rx, ry. -; Finally draw the last straight line. -L2477: - call STACK_TO_BC ;;Pops x, and y, and stores it in B, C - ld hl, (COORDS) ;;Calculates x2 and y2 in L, H - - rl e ;; Rotate left to carry - ld a, c - jr nc, SUM_C - neg -SUM_C: - add a, l - ld l, a ;; X2 - - rl d ;; Low sign to carry - ld a, b - jr nc, SUM_B - neg -SUM_B: - add a, h - ld h, a - jp __DRAW ;;forward to LINE-DRAW (Fastcalled) - - ENDP - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/error.asm b/src/lib/arch/zxnext/runtime/error.asm index e603d5477..475ccaa81 100644 --- a/src/lib/arch/zxnext/runtime/error.asm +++ b/src/lib/arch/zxnext/runtime/error.asm @@ -1,44 +1,8 @@ -; Simple error control routines -; vim:ts=4:et: - - push namespace core - -ERR_NR EQU 23610 ; Error code system variable - - -; Error code definitions (as in ZX spectrum manual) - -; Set error code with: -; ld a, ERROR_CODE -; ld (ERR_NR), a - - -ERROR_Ok EQU -1 -ERROR_SubscriptWrong EQU 2 -ERROR_OutOfMemory EQU 3 -ERROR_OutOfScreen EQU 4 -ERROR_NumberTooBig EQU 5 -ERROR_InvalidArg EQU 9 -ERROR_IntOutOfRange EQU 10 -ERROR_NonsenseInBasic EQU 11 -ERROR_InvalidFileName EQU 14 -ERROR_InvalidColour EQU 19 -ERROR_BreakIntoProgram EQU 20 -ERROR_TapeLoadingErr EQU 26 - - -; Raises error using RST #8 -__ERROR: - ld (__ERROR_CODE), a - rst 8 -__ERROR_CODE: - nop - ret - -; Sets the error system variable, but keeps running. -; Usually this instruction if followed by the END intermediate instruction. -__STOP: - ld (ERR_NR), a - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/f16tofreg.asm b/src/lib/arch/zxnext/runtime/f16tofreg.asm index 97ab00997..1aa615330 100644 --- a/src/lib/arch/zxnext/runtime/f16tofreg.asm +++ b/src/lib/arch/zxnext/runtime/f16tofreg.asm @@ -1,52 +1,8 @@ -#include once -#include once - - push namespace core - -__F16TOFREG: ; Converts a 16.16 signed fixed point (stored in DEHL) - ; to a Floating Point Number returned in (C ED CB) - PROC - - LOCAL __F16TOFREG2 - - ld a, d - or a ; Test sign - - jp p, __F16TOFREG2 ; It was positive, proceed as 32bit unsigned - - call __NEG32 ; Convert it to positive - call __F16TOFREG2 ; Convert it to Floating point - - set 7, e ; Put the sign bit (negative) in the 31bit of mantissa - ret - - -__F16TOFREG2: ; Converts an unsigned 32 bit integer (DEHL) - ; to a Floating point number returned in C DE HL - - ld a, d - or e - or h - or l - ld b, h - ld c, l - ret z ; Return 00 0000 0000 if 0 - - push de - push hl - - exx - pop de ; Loads integer into B'C' D'E' - pop bc - exx - - ld l, 112 ; Exponent - ld bc, 0 ; DEBC = 0 - ld d, b - ld e, c - jp __U32TOFREG_LOOP ; Proceed as an integer - - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/flash.asm b/src/lib/arch/zxnext/runtime/flash.asm index 2ba5a7e53..c4b28606c 100644 --- a/src/lib/arch/zxnext/runtime/flash.asm +++ b/src/lib/arch/zxnext/runtime/flash.asm @@ -1,47 +1,8 @@ -; Sets flash flag in ATTR_P permanently -; Parameter: Paper color in A register - -#include once - - push namespace core - -FLASH: - ld hl, ATTR_P - - PROC - LOCAL IS_TR - LOCAL IS_ZERO - -__SET_FLASH: - ; Another entry. This will set the flash flag at location pointer by DE - cp 8 - jr z, IS_TR - - ; # Convert to 0/1 - or a - jr z, IS_ZERO - ld a, 0x80 - -IS_ZERO: - ld b, a ; Saves the color - ld a, (hl) - and 07Fh ; Clears previous value - or b - ld (hl), a - inc hl - res 7, (hl) ;Reset bit 7 to disable transparency - ret - -IS_TR: ; transparent - inc hl ; Points DE to MASK_T or MASK_P - set 7, (hl) ;Set bit 7 to enable transparency - ret - -; Sets the FLASH flag passed in A register in the ATTR_T variable -FLASH_TMP: - ld hl, ATTR_T - jr __SET_FLASH - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/ftof16reg.asm b/src/lib/arch/zxnext/runtime/ftof16reg.asm index b1b19f9fb..2a80b544e 100644 --- a/src/lib/arch/zxnext/runtime/ftof16reg.asm +++ b/src/lib/arch/zxnext/runtime/ftof16reg.asm @@ -1,46 +1,8 @@ -#include once - - push namespace core - -__FTOF16REG: ; Converts a Float to 16.16 (32 bit) fixed point decimal - ; Input FP number in A EDCB (A exponent, EDCB mantissa) - - ld l, a ; Saves exponent for later - or d - or e - or b - or c - ld h, e - ret z ; Return if ZERO - - push hl ; Stores it for later (Contains sign in H, exponent in L) - - push de - push bc - - exx - pop de ; Loads mantissa into C'B' E'D' - pop bc ; - - set 7, c ; Highest mantissa bit is always 1 - exx - - ld hl, 0 ; DEHL = 0 - ld d, h - ld e, l - - pop bc - - ld a, c ; Get exponent - sub 112 ; Exponent -= 128 + 16 - - push bc ; Saves sign in b again - - jp z, __FTOU32REG_END ; If it was <= 128, we are done (Integers must be > 128) - jp c, __FTOU32REG_END ; It was decimal (0.xxx). We are done (return 0) - - ld b, a ; Loop counter = exponent - 128 + 16 (we need to shift 16 bit more) - jp __FTOU32REG_LOOP ; proceed as an u32 integer - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/ftou32reg.asm b/src/lib/arch/zxnext/runtime/ftou32reg.asm index ab84e3072..304f702d4 100644 --- a/src/lib/arch/zxnext/runtime/ftou32reg.asm +++ b/src/lib/arch/zxnext/runtime/ftou32reg.asm @@ -1,94 +1,8 @@ -#include once - - push namespace core - -__FTOU32REG: ; Converts a Float to (un)signed 32 bit integer (NOTE: It's ALWAYS 32 bit signed) - ; Input FP number in A EDCB (A exponent, EDCB mantissa) - ; Output: DEHL 32 bit number (signed) - PROC - - LOCAL __IS_FLOAT - LOCAL __NEGATE - - or a - jr nz, __IS_FLOAT - ; Here if it is a ZX ROM Integer - - ld h, c - ld l, d - ld d, e - ret - -__IS_FLOAT: ; Jumps here if it is a true floating point number - ld h, e - push hl ; Stores it for later (Contains Sign in H) - - push de - push bc - - exx - pop de ; Loads mantissa into C'B' E'D' - pop bc ; - - set 7, c ; Highest mantissa bit is always 1 - exx - - ld hl, 0 ; DEHL = 0 - ld d, h - ld e, l - - ;ld a, c ; Get exponent - sub 128 ; Exponent -= 128 - jr z, __FTOU32REG_END ; If it was <= 128, we are done (Integers must be > 128) - jr c, __FTOU32REG_END ; It was decimal (0.xxx). We are done (return 0) - - ld b, a ; Loop counter = exponent - 128 - -__FTOU32REG_LOOP: - exx ; Shift C'B' E'D' << 1, output bit stays in Carry - sla d - rl e - rl b - rl c - - exx ; Shift DEHL << 1, inserting the carry on the right - rl l - rl h - rl e - rl d - - djnz __FTOU32REG_LOOP - -__FTOU32REG_END: - pop af ; Take the sign bit - or a ; Sets SGN bit to 1 if negative - jp m, __NEGATE ; Negates DEHL - - ret - -__NEGATE: - exx - ld a, d - or e - or b - or c - exx - jr z, __END - inc l - jr nz, __END - inc h - jr nz, __END - inc de -LOCAL __END -__END: - jp __NEG32 - ENDP - - -__FTOU8: ; Converts float in C ED LH to Unsigned byte in A - call __FTOU32REG - ld a, l - ret - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/iload32.asm b/src/lib/arch/zxnext/runtime/iload32.asm index a647bcdc9..bfd142743 100644 --- a/src/lib/arch/zxnext/runtime/iload32.asm +++ b/src/lib/arch/zxnext/runtime/iload32.asm @@ -1,21 +1,8 @@ -; __FASTCALL__ routine which -; loads a 32 bits integer into DE,HL -; stored at position pointed by POINTER HL -; DE,HL <-- (HL) - - push namespace core - -__ILOAD32: - ld e, (hl) - inc hl - ld d, (hl) - inc hl - ld a, (hl) - inc hl - ld h, (hl) - ld l, a - ex de, hl - ret - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/iloadf.asm b/src/lib/arch/zxnext/runtime/iloadf.asm index b425e3588..32ff8669b 100644 --- a/src/lib/arch/zxnext/runtime/iloadf.asm +++ b/src/lib/arch/zxnext/runtime/iloadf.asm @@ -1,32 +1,8 @@ -; __FASTCALL__ routine which -; loads a 40 bits floating point into A ED CB -; stored at position pointed by POINTER HL -;A DE, BC <-- ((HL)) - - push namespace core - -__ILOADF: - ld a, (hl) - inc hl - ld h, (hl) - ld l, a - -; __FASTCALL__ routine which -; loads a 40 bits floating point into A ED CB -; stored at position pointed by POINTER HL -;A DE, BC <-- (HL) - -__LOADF: ; Loads a 40 bits FP number from address pointed by HL - ld a, (hl) - inc hl - ld e, (hl) - inc hl - ld d, (hl) - inc hl - ld c, (hl) - inc hl - ld b, (hl) - ret - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/in_screen.asm b/src/lib/arch/zxnext/runtime/in_screen.asm index 724450c7a..ece104e67 100644 --- a/src/lib/arch/zxnext/runtime/in_screen.asm +++ b/src/lib/arch/zxnext/runtime/in_screen.asm @@ -1,30 +1,8 @@ -#include once -#include once - - push namespace core - -__IN_SCREEN: - ; Returns NO carry if current coords (D, E) - ; are OUT of the screen limits - - PROC - LOCAL __IN_SCREEN_ERR - - ld hl, SCR_SIZE - ld a, e - cp l - jr nc, __IN_SCREEN_ERR ; Do nothing and return if out of range - - ld a, d - cp h - ret c ; Return if carry (OK) - -__IN_SCREEN_ERR: -__OUT_OF_SCREEN_ERR: - ; Jumps here if out of screen - ld a, ERROR_OutOfScreen - jp __STOP ; Saves error code and exits - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/ink.asm b/src/lib/arch/zxnext/runtime/ink.asm index 7dcb64113..286ba4231 100644 --- a/src/lib/arch/zxnext/runtime/ink.asm +++ b/src/lib/arch/zxnext/runtime/ink.asm @@ -1,47 +1,8 @@ -; Sets ink color in ATTR_P permanently -; Parameter: Paper color in A register - -#include once - - push namespace core - -INK: - PROC - LOCAL __SET_INK - LOCAL __SET_INK2 - - ld de, ATTR_P - -__SET_INK: - cp 8 - jr nz, __SET_INK2 - - inc de ; Points DE to MASK_T or MASK_P - ld a, (de) - or 7 ; Set bits 0,1,2 to enable transparency - ld (de), a - ret - -__SET_INK2: - ; Another entry. This will set the ink color at location pointer by DE - and 7 ; # Gets color mod 8 - ld b, a ; Saves the color - ld a, (de) - and 0F8h ; Clears previous value - or b - ld (de), a - inc de ; Points DE to MASK_T or MASK_P - ld a, (de) - and 0F8h ; Reset bits 0,1,2 sign to disable transparency - ld (de), a ; Store new attr - ret - -; Sets the INK color passed in A register in the ATTR_T variable -INK_TMP: - ld de, ATTR_T - jp __SET_INK - - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/inverse.asm b/src/lib/arch/zxnext/runtime/inverse.asm index 974a0c5bc..f9bbedcad 100644 --- a/src/lib/arch/zxnext/runtime/inverse.asm +++ b/src/lib/arch/zxnext/runtime/inverse.asm @@ -1,35 +1,8 @@ -; Sets INVERSE flag in P_FLAG permanently -; Parameter: INVERSE flag in bit 0 of A register - -#include once - - push namespace core - -INVERSE: - PROC - - and 1 ; # Convert to 0/1 - add a, a; # Shift left 3 bits for permanent - add a, a - add a, a - ld hl, P_FLAG - res 3, (hl) - or (hl) - ld (hl), a - ret - -; Sets INVERSE flag in P_FLAG temporarily -INVERSE_TMP: - and 1 - add a, a - add a, a; # Shift left 2 bits for temporary - ld hl, P_FLAG - res 2, (hl) - or (hl) - ld (hl), a - jp __SET_ATTR_MODE - - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/io/keyboard/inkey.asm b/src/lib/arch/zxnext/runtime/io/keyboard/inkey.asm index 8ab774f8b..e09b4e8e9 100644 --- a/src/lib/arch/zxnext/runtime/io/keyboard/inkey.asm +++ b/src/lib/arch/zxnext/runtime/io/keyboard/inkey.asm @@ -1,63 +1,8 @@ -; INKEY Function -; Returns a string allocated in dynamic memory -; containing the string. -; An empty string otherwise. - -#include once - - push namespace core - -INKEY: - PROC - LOCAL __EMPTY_INKEY - LOCAL KEY_SCAN - LOCAL KEY_TEST - LOCAL KEY_CODE - - ld bc, 3 ; 1 char length string - call __MEM_ALLOC - - ld a, h - or l - ret z ; Return if NULL (No memory) - - push hl ; Saves memory pointer - - call KEY_SCAN - jp nz, __EMPTY_INKEY - - call KEY_TEST - jp nc, __EMPTY_INKEY - - dec d ; D is expected to be FLAGS so set bit 3 $FF - ; 'L' Mode so no keywords. - ld e, a ; main key to A - ; C is MODE 0 'KLC' from above still. - call KEY_CODE ; routine K-DECODE - pop hl - - ld (hl), 1 - inc hl - ld (hl), 0 - inc hl - ld (hl), a - dec hl - dec hl ; HL Points to string result - ret - -__EMPTY_INKEY: - pop hl - xor a - ld (hl), a - inc hl - ld (hl), a - dec hl - ret - -KEY_SCAN EQU 028Eh -KEY_TEST EQU 031Eh -KEY_CODE EQU 0333h - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/io/sound/beep.asm b/src/lib/arch/zxnext/runtime/io/sound/beep.asm index 71124c1ed..c58f37a15 100644 --- a/src/lib/arch/zxnext/runtime/io/sound/beep.asm +++ b/src/lib/arch/zxnext/runtime/io/sound/beep.asm @@ -1,24 +1,8 @@ -#include once - - push namespace core - -BEEP: ; The beep command, as in BASIC - ; Duration in C,ED,LH (float) - ; Pitch in top of the stack - - CALL __FPSTACK_PUSH - - pop hl ; RET address - pop af - pop de - pop bc ; Recovers PITCH from the stack - push hl ; CALLEE, now ret addr in top of the stack - - CALL __FPSTACK_PUSH ; Pitch onto the FP stack - - push ix ; BEEP routine modifies IX. We have to preserve it - call 03F8h - pop ix - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/io/sound/beeper.asm b/src/lib/arch/zxnext/runtime/io/sound/beeper.asm index b879ada72..78633e75a 100644 --- a/src/lib/arch/zxnext/runtime/io/sound/beeper.asm +++ b/src/lib/arch/zxnext/runtime/io/sound/beeper.asm @@ -1,20 +1,8 @@ -; vim:ts=4:et:sw=4: -; This is a fast beep routine, but needs parameters -; codified in a different way. -; See http://www.wearmouth.demon.co.uk/zx82.htm#L03F8 - -; Needs pitch on top of the stack -; HL = duration - - push namespace core - -__BEEPER: - ex de, hl - pop hl - ex (sp), hl ; CALLEE - push ix ; BEEPER changes IX - call 03B5h - pop ix - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/istore16.asm b/src/lib/arch/zxnext/runtime/istore16.asm index e2a918c24..8c1916c13 100644 --- a/src/lib/arch/zxnext/runtime/istore16.asm +++ b/src/lib/arch/zxnext/runtime/istore16.asm @@ -1,20 +1,8 @@ - push namespace core - -__PISTORE16: ; stores an integer in hl into address IX + BC; Destroys DE - ex de, hl - push ix - pop hl - add hl, bc - -__ISTORE16: ; Load address at hl, and stores E,D integer at that address - ld a, (hl) - inc hl - ld h, (hl) - ld l, a - ld (hl), e - inc hl - ld (hl), d - ret - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/italic.asm b/src/lib/arch/zxnext/runtime/italic.asm index 5d24dae13..c7398bc84 100644 --- a/src/lib/arch/zxnext/runtime/italic.asm +++ b/src/lib/arch/zxnext/runtime/italic.asm @@ -1,36 +1,8 @@ -; Sets ITALIC flag in P_FLAG permanently -; Parameter: ITALIC flag in bit 0 of A register -#include once - - push namespace core - -ITALIC: - PROC - - and 1 - rrca - rrca - rrca - ld hl, FLAGS2 - res 5, (HL) - or (hl) - ld (hl), a - ret - -; Sets ITALIC flag in P_FLAG temporarily -ITALIC_TMP: - and 1 - rrca - rrca - rrca - rrca - ld hl, FLAGS2 - res 4, (hl) - or (hl) - ld (hl), a - ret - - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/lddede.asm b/src/lib/arch/zxnext/runtime/lddede.asm index 4718f2fcf..71a4b7394 100644 --- a/src/lib/arch/zxnext/runtime/lddede.asm +++ b/src/lib/arch/zxnext/runtime/lddede.asm @@ -1,17 +1,8 @@ -; Loads DE into DE -; Modifies C register -; There is a routine similar to this one -; at ROM address L2AEE - push namespace core - -__LOAD_DE_DE: - ex de, hl - ld c, (hl) - inc hl - ld h, (hl) - ld l, c - ex de, hl - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/letsubstr.asm b/src/lib/arch/zxnext/runtime/letsubstr.asm index 4a0a3e7f6..b56b9e6f6 100644 --- a/src/lib/arch/zxnext/runtime/letsubstr.asm +++ b/src/lib/arch/zxnext/runtime/letsubstr.asm @@ -1,157 +1,8 @@ -; Substring assigment eg. LET a$(p0 TO p1) = "xxxx" -; HL = Start of string -; TOP of the stack -> p1 (16 bit, unsigned) -; TOP -1 of the stack -> p0 register -; TOP -2 Flag (popped out in A register) -; A Register => 0 if HL is not freed from memory -; => Not 0 if HL must be freed from memory on exit -; TOP -3 B$ address - -#include once - - push namespace core - -__LETSUBSTR: - PROC - - LOCAL __CONT0 - LOCAL __CONT1 - LOCAL __CONT2 - LOCAL __FREE_STR - - exx - pop hl ; Return address - pop de ; p1 - pop bc ; p0 - exx - - pop af ; Flag - ex af, af' ; Save it for later - - pop de ; B$ - - exx - push hl ; push ret addr back - exx - push de ; B$ addr to be freed upon return (if A != 0) - - ld a, h - or l - jp z, __FREE_STR ; Return if null - - ld c, (hl) - inc hl - ld b, (hl) ; BC = Str length - inc hl ; HL = String start - push bc - - exx - ex de, hl - or a - sbc hl, bc ; HL = Length of string requested by user - inc hl ; len (a$(p0 TO p1)) = p1 - p0 + 1 - ex de, hl ; Saves it in DE - - pop hl ; HL = String length - exx - jp c, __FREE_STR ; Return if p0 > p1 - exx - - or a - sbc hl, bc ; P0 >= String length? - exx - - jp z, __FREE_STR ; Return if equal - jp c, __FREE_STR ; Return if greater - - exx - add hl, bc ; Add it back - - sbc hl, de ; Length of substring > string => Truncate it - add hl, de ; add it back - jr nc, __CONT0 ; Length of substring within a$ - - ld d, h - ld e, l ; Truncate length of substring to fit within the strlen - -__CONT0: ; At this point DE = Length of substring to copy - ; BC = start of char to copy - push de - - push bc - exx - pop bc - - add hl, bc ; Start address (within a$) so copy from b$ (in DE) - - push hl - exx - pop hl ; Start address (within a$) so copy from b$ (in DE) - - ld b, d ; Length of string - ld c, e - - ld (hl), ' ' - ld d, h - ld e, l - inc de - dec bc - ld a, b - or c - jr z, __CONT2 - - ; At this point HL = DE = Start of Write zone in a$ - ; BC = Number of chars to write - - ldir - -__CONT2: - - pop bc ; Recovers Length of string to copy - exx - ex de, hl ; HL = Source, DE = Target - - ld a, h - or l - jp z, __FREE_STR ; Return if B$ is NULL - - ld c, (hl) - inc hl - ld b, (hl) - inc hl - - ld a, b - or c - jp z, __FREE_STR ; Return if len(b$) = 0 - - ; Now if len(b$) < len(char to copy), copy only len(b$) chars - - push de - push hl - push bc - exx - pop hl ; LEN (b$) - or a - sbc hl, bc - add hl, bc - jr nc, __CONT1 - - ; If len(b$) < len(to copy) - ld b, h ; BC = len(to copy) - ld c, l - -__CONT1: - pop hl - pop de - ldir ; Copy b$ into a$(x to y) - -__FREE_STR: - pop hl - ex af, af' - or a ; If not 0, free - jp nz, __MEM_FREE - ret - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/load.asm b/src/lib/arch/zxnext/runtime/load.asm index ce6e97733..84a302f7a 100644 --- a/src/lib/arch/zxnext/runtime/load.asm +++ b/src/lib/arch/zxnext/runtime/load.asm @@ -1,335 +1,8 @@ -#include once - -#ifndef HIDE_LOAD_MSG -# include once -#endif - - push namespace core - -LOAD_CODE: -; This function will implement the LOAD CODE Routine -; Parameters in the stack are HL => String with LOAD name -; (only first 12 chars will be taken into account) -; DE = START address of CODE to save -; BC = Length of data in bytes -; A = 1 => LOAD 0 => Verify - - PROC - - LOCAL LOAD_CONT, LOAD_CONT2, LOAD_CONT3 - LOCAL LD_BYTES - LOCAL LOAD_HEADER - LOCAL LD_LOOK_H - LOCAL HEAD1 - LOCAL TMP_HEADER - LOCAL LD_NAME - LOCAL LD_CH_PR - LOCAL LOAD_END - LOCAL VR_CONTROL, VR_CONT_1, VR_CONT_2 - LOCAL MEM0 - LOCAL TMP_SP - -MEM0 EQU 5C92h ; Temporary memory buffer -HEAD1 EQU MEM0 + 8 ; Uses CALC Mem for temporary storage - ; Must skip first 8 bytes used by - ; PRINT routine -TMP_HEADER EQU HEAD1 + 17 ; Temporary HEADER2 pointer storage -TMP_SP EQU TMP_HEADER + 2 ; Temporary SP storage - -#ifdef __ENABLE_BREAK__ -LD_BYTES EQU 0556h ; ROM Routine LD-BYTES -#endif - -TMP_FLAG EQU 23655 ; Uses BREG as a Temporary FLAG - - pop hl ; Return address - pop af ; A = 1 => LOAD; A = 0 => VERIFY - pop bc ; data length in bytes - pop de ; address start - ex (sp), hl ; CALLE => now hl = String - -__LOAD_CODE: ; INLINE version - push ix ; saves IX - ld (TMP_FLAG), a ; Stores verify/load flag - - ; Prepares temporary 1st header descriptor - ld ix, HEAD1 - ld (ix + 0), 3 ; ZXBASIC ALWAYS uses CODE - ld (ix + 1), 0FFh ; Wildcard for empty string - - ld (ix + 11), c - ld (ix + 12), b ; Store length in bytes - ld (ix + 13), e - ld (ix + 14), d ; Store address in bytes - - push hl ; String ptr to be freed later - - ld a, h - or l - ld b, h - ld c, l - jr z, LOAD_HEADER ; NULL STRING => LOAD "" - - ld c, (hl) - inc hl - ld b, (hl) - inc hl - - ld a, b - or c - jr z, LOAD_CONT2 ; NULL STRING => LOAD "" - - ; Fill with blanks - push hl - push bc - ld hl, HEAD1 + 2 - ld de, HEAD1 + 3 - ld bc, 8 - ld (hl), ' ' - ldir - pop bc - pop hl - -LOAD_HEADER: - ex de, hl ; Saves HL in DE - ld hl, 10 - or a - sbc hl, bc ; Test BC > 10? - ex de, hl ; Retrieve HL - jr nc, LOAD_CONT ; Ok BC <= 10 - ld bc, 10 ; BC at most 10 chars - -LOAD_CONT: - ld de, HEAD1 + 1 - ldir ; Copy String block NAME in header - -LOAD_CONT2: - pop hl ; String ptr - call MEM_FREE - - ld hl, 0 - add hl, sp - ld (TMP_SP), hl - ld bc, -18 - add hl, bc - ld sp, hl - -LOAD_CONT3: - ld (TMP_HEADER), hl - push hl - pop ix - -;; LD-LOOK-H --- RIPPED FROM ROM at 0x767 -LD_LOOK_H: - push ix ; save IX - ld de, 17 ; seventeen bytes - xor a ; reset zero flag - scf ; set carry flag - - call LD_BYTES ; routine LD-BYTES loads a header from tape - ; to second descriptor. - pop ix ; restore IX - jr nc, LD_LOOK_H ; loop back to LD-LOOK-H until header found. - - ld c, 80h ; C has bit 7 set to indicate header type mismatch as - ; a default startpoint. - - ld a, (ix + 0) ; compare loaded type - cp 3 ; with expected bytes header - jr nz, LD_TYPE ; forward to LD-TYPE with mis-match. - - ld c, -10 ; set C to minus ten - will count characters - ; up to zero. -LD_TYPE: - cp 4 ; check if type in acceptable range 0 - 3. - jr nc, LD_LOOK_H ; back to LD-LOOK-H with 4 and over. - ; else A indicates type 0-3. -#ifndef HIDE_LOAD_MSG - call PRINT_TAPE_MESSAGES; Print tape msg -#endif - - ld hl, HEAD1 + 1 ; point HL to 1st descriptor. - ld de, (TMP_HEADER) ; point DE to 2nd descriptor. - ld b, 10 ; the count will be ten characters for the - ; filename. - - ld a, (hl) ; fetch first character and test for - inc a ; value 255. - jr nz, LD_NAME ; forward to LD-NAME if not the wildcard. - -; but if it is the wildcard, then add ten to C which is minus ten for a type -; match or -128 for a type mismatch. Although characters have to be counted -; bit 7 of C will not alter from state set here. - - ld a, c ; transfer $F6 or $80 to A - add a, b ; add 10 - ld c, a ; place result, zero or -118, in C. - -; At this point we have either a type mismatch, a wildcard match or ten -; characters to be counted. The characters must be shown on the screen. - -;; LD-NAME -LD_NAME: - inc de ; address next input character - ld a, (de) ; fetch character - cp (hl) ; compare to expected - inc hl ; address next expected character - jr nz, LD_CH_PR ; forward to LD-CH-PR with mismatch - - inc c ; increment matched character count - -;; LD-CH-PR -LD_CH_PR: -#ifndef HIDE_LOAD_MSG - call __PRINTCHAR ; PRINT-A prints character -#endif - djnz LD_NAME ; loop back to LD-NAME for ten characters. - - bit 7, c ; test if all matched - jr nz, LD_LOOK_H ; back to LD-LOOK-H if not - -; else print a terminal carriage return. - -#ifndef HIDE_LOAD_MSG - ld a, 0Dh ; prepare carriage return. - call __PRINTCHAR ; PRINT-A outputs it. -#endif - - ld a, (HEAD1) - cp 03 ; Only "bytes:" header is used un ZX BASIC - jr nz, LD_LOOK_H - - ; Ok, ready to check for bytes start and end - -VR_CONTROL: - ld e, (ix + 11) ; fetch length of new data - ld d, (ix + 12) ; to DE. - - ld hl, HEAD1 + 11 - ld a, (hl) ; fetch length of old data (orig. header) - inc hl - ld h, (hl) ; to HL - ld l, a - or h ; check length of old for zero. (Carry reset) - jr z, VR_CONT_1 ; forward to VR-CONT-1 if length unspecified - ; e.g. LOAD "x" CODE - sbc hl, de - jr nz, LOAD_ERROR ; Lengths don't match - -VR_CONT_1: - ld hl, HEAD1 + 13 ; fetch start of old data (orig. header) - ld a, (hl) - inc hl - ld h, (hl) - ld l, a - or h ; check start for zero (unspecified) - jr nz, VR_CONT_2 ; Jump if there was a start - - ld l, (ix + 13) ; otherwise use destination in header - ld h, (ix + 14) ; and load code at addr. saved from - -VR_CONT_2: - push hl - pop ix ; Transfer load addr to IX - - ld a, (TMP_FLAG) ; load verify/load flag - sra a ; shift bit 0 to Carry (1 => Load, 0 = Verify), A = 0 - dec a ; a = 0xFF (Data) - call LD_BYTES - jr c, LOAD_END ; if carry, load/verification was ok - -LOAD_ERROR: - ; Sets ERR_NR with Tape Loading, and returns - ld a, ERROR_TapeLoadingErr - ld (ERR_NR), a - -LOAD_END: - ld hl, (TMP_SP) - ld sp, hl ; Recovers stack - pop ix ; Recovers stack frame pointer - ret - -#ifndef __ENABLE_BREAK__ - LOCAL LD_BYTES_RET - LOCAL LD_BYTES_ROM - LOCAL LD_BYTES_NOINTER - -LD_BYTES_ROM EQU 0562h - -LD_BYTES: - - inc d - ex af, af' - dec d - ld a, r - push af - di - call 0562h - -LD_BYTES_RET: - ; Restores DI / EI state - ex af, af' - pop af - jp po, LD_BYTES_NOINTER - ei - -LD_BYTES_NOINTER: - ex af, af' - ret -#endif - ENDP - - -#ifndef HIDE_LOAD_MSG -PRINT_TAPE_MESSAGES: - - PROC - - LOCAL LOOK_NEXT_TAPE_MSG - LOCAL PRINT_TAPE_MSG - - ; Print tape messages according to A value - ; Each message starts with a carriage return and - ; ends with last char having its bit 7 set - - ; A = 0 => '\nProgram: ' - ; A = 1 => '\nNumber array: ' - ; A = 2 => '\nCharacter array: ' - ; A = 3 => '\nBytes: ' - - push bc - - ld hl, 09C0h ; address base of last 4 tape messages - ld b, a - inc b ; avoid 256-loop if b == 0 - ld a, 0Dh ; Msg start mark - - ; skip memory bytes looking for next tape msg entry - ; each msg ends when 0Dh is fond -LOOK_NEXT_TAPE_MSG: - inc hl ; Point to next char - cp (hl) ; Is it 0Dh? - jr nz, LOOK_NEXT_TAPE_MSG - ; Ok next message found - djnz LOOK_NEXT_TAPE_MSG ; Repeat if more msg to skip - -PRINT_TAPE_MSG: - ; Ok. This will print bytes after (HL) - ; until one of them has bit 7 set - ld a, (hl) - and 7Fh ; Clear bit 7 of A - call __PRINTCHAR - - ld a, (hl) - inc hl - add a, a ; Carry if A >= 128 - jr nc, PRINT_TAPE_MSG - - pop bc - ret - - ENDP - -#endif - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/loadstr.asm b/src/lib/arch/zxnext/runtime/loadstr.asm index ae597951f..c6fd13711 100644 --- a/src/lib/arch/zxnext/runtime/loadstr.asm +++ b/src/lib/arch/zxnext/runtime/loadstr.asm @@ -1,47 +1,8 @@ -#include once - -; Loads a string (ptr) from HL -; and duplicates it on dynamic memory again -; Finally, it returns result pointer in HL - - push namespace core - -__ILOADSTR: ; This is the indirect pointer entry HL = (HL) - ld a, h - or l - ret z - ld a, (hl) - inc hl - ld h, (hl) - ld l, a - -__LOADSTR: ; __FASTCALL__ entry - ld a, h - or l - ret z ; Return if NULL - - ld c, (hl) - inc hl - ld b, (hl) - dec hl ; BC = LEN(a$) - - inc bc - inc bc ; BC = LEN(a$) + 2 (two bytes for length) - - push hl - push bc - call __MEM_ALLOC - pop bc ; Recover length - pop de ; Recover origin - - ld a, h - or l - ret z ; Return if NULL (No memory) - - ex de, hl ; ldir takes HL as source, DE as destiny, so SWAP HL,DE - push de ; Saves destiny start - ldir ; Copies string (length number included) - pop hl ; Recovers destiny in hl as result - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/math/acos.asm b/src/lib/arch/zxnext/runtime/math/acos.asm index 36f7169ad..4d11d63a4 100644 --- a/src/lib/arch/zxnext/runtime/math/acos.asm +++ b/src/lib/arch/zxnext/runtime/math/acos.asm @@ -1,14 +1,8 @@ -#include once - - push namespace core - -ACOS: ; Computes ACOS using ROM FP-CALC - call __FPSTACK_PUSH - - rst 28h ; ROM CALC - defb 23h ; ACOS - defb 38h ; END CALC - - jp __FPSTACK_POP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/math/asin.asm b/src/lib/arch/zxnext/runtime/math/asin.asm index a41b236b7..dd5a4023a 100644 --- a/src/lib/arch/zxnext/runtime/math/asin.asm +++ b/src/lib/arch/zxnext/runtime/math/asin.asm @@ -1,14 +1,8 @@ -#include once - - push namespace core - -ASIN: ; Computes ASIN using ROM FP-CALC - call __FPSTACK_PUSH - - rst 28h ; ROM CALC - defb 22h ; ASIN - defb 38h ; END CALC - - jp __FPSTACK_POP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/math/atan.asm b/src/lib/arch/zxnext/runtime/math/atan.asm index c73b56939..d3f9a3daf 100644 --- a/src/lib/arch/zxnext/runtime/math/atan.asm +++ b/src/lib/arch/zxnext/runtime/math/atan.asm @@ -1,14 +1,8 @@ -#include once - - push namespace core - -ATAN: ; Computes ATAN using ROM FP-CALC - call __FPSTACK_PUSH - - rst 28h ; ROM CALC - defb 24h ; ATAN - defb 38h ; END CALC - - jp __FPSTACK_POP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/math/cos.asm b/src/lib/arch/zxnext/runtime/math/cos.asm index 4a62f1947..37d8d0248 100644 --- a/src/lib/arch/zxnext/runtime/math/cos.asm +++ b/src/lib/arch/zxnext/runtime/math/cos.asm @@ -1,14 +1,8 @@ -#include once - - push namespace core - -COS: ; Computes COS using ROM FP-CALC - call __FPSTACK_PUSH - - rst 28h ; ROM CALC - defb 20h ; COS - defb 38h ; END CALC - - jp __FPSTACK_POP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/math/exp.asm b/src/lib/arch/zxnext/runtime/math/exp.asm index 052b38984..7a75bc8d0 100644 --- a/src/lib/arch/zxnext/runtime/math/exp.asm +++ b/src/lib/arch/zxnext/runtime/math/exp.asm @@ -1,14 +1,8 @@ -#include once - - push namespace core - -EXP: ; Computes e^n using ROM FP-CALC - call __FPSTACK_PUSH - - rst 28h ; ROM CALC - defb 26h ; E^n - defb 38h ; END CALC - - jp __FPSTACK_POP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/math/logn.asm b/src/lib/arch/zxnext/runtime/math/logn.asm index 1f12fa2e9..6a2b33a54 100644 --- a/src/lib/arch/zxnext/runtime/math/logn.asm +++ b/src/lib/arch/zxnext/runtime/math/logn.asm @@ -1,14 +1,8 @@ -#include once - - push namespace core - -LN: ; Computes Ln(x) using ROM FP-CALC - call __FPSTACK_PUSH - - rst 28h ; ROM CALC - defb 25h - defb 38h ; END CALC - - jp __FPSTACK_POP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/math/pow.asm b/src/lib/arch/zxnext/runtime/math/pow.asm index f6119c66d..8ec3bd2ac 100644 --- a/src/lib/arch/zxnext/runtime/math/pow.asm +++ b/src/lib/arch/zxnext/runtime/math/pow.asm @@ -1,34 +1,8 @@ -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses A EDCB registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order A DE BC. -; -; Uses CALLEE convention +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Operands comes swapped: -; 1 st parameter is the BASE (A ED CB) -; 2 nd parameter (Top of the stack) is Exponent -; ------------------------------------------------------------- - - push namespace core - -__POW: ; Exponentiation - PROC - - call __FPSTACK_PUSH2 - - ; ------------- ROM POW - rst 28h - defb 01h ; Exchange => 1, Base - defb 06h ; POW - defb 38h; ; END CALC - - jp __FPSTACK_POP - - ENDP +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/math/sin.asm b/src/lib/arch/zxnext/runtime/math/sin.asm index 59ed05661..1e5d90661 100644 --- a/src/lib/arch/zxnext/runtime/math/sin.asm +++ b/src/lib/arch/zxnext/runtime/math/sin.asm @@ -1,14 +1,8 @@ -#include once - - push namespace core - -SIN: ; Computes SIN using ROM FP-CALC - call __FPSTACK_PUSH - - rst 28h ; ROM CALC - defb 1Fh - defb 38h ; END CALC - - jp __FPSTACK_POP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/math/sqrt.asm b/src/lib/arch/zxnext/runtime/math/sqrt.asm index 4ddbc1b54..84dd2bb7b 100644 --- a/src/lib/arch/zxnext/runtime/math/sqrt.asm +++ b/src/lib/arch/zxnext/runtime/math/sqrt.asm @@ -1,14 +1,8 @@ -#include once - - push namespace core - -SQRT: ; Computes SQRT(x) using ROM FP-CALC - call __FPSTACK_PUSH - - rst 28h ; ROM CALC - defb 28h ; SQRT - defb 38h ; END CALC - - jp __FPSTACK_POP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/math/tan.asm b/src/lib/arch/zxnext/runtime/math/tan.asm index 4da8c9414..68d4860f8 100644 --- a/src/lib/arch/zxnext/runtime/math/tan.asm +++ b/src/lib/arch/zxnext/runtime/math/tan.asm @@ -1,14 +1,8 @@ -#include once - - push namespace core - -TAN: ; Computes TAN using ROM FP-CALC - call __FPSTACK_PUSH - - rst 28h ; ROM CALC - defb 21h ; TAN - defb 38h ; END CALC - - jp __FPSTACK_POP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/mem/calloc.asm b/src/lib/arch/zxnext/runtime/mem/calloc.asm index fbda2cb17..428d3a41b 100644 --- a/src/lib/arch/zxnext/runtime/mem/calloc.asm +++ b/src/lib/arch/zxnext/runtime/mem/calloc.asm @@ -1,49 +1,8 @@ -; vim: ts=4:et:sw=4: -; Copyleft (K) by Jose M. Rodriguez de la Rosa -; (a.k.a. Boriel) -; http://www.boriel.com +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; This ASM library is licensed under the MIT license -; you can use it for any purpose (even for commercial -; closed source programs). -; -; Please read the MIT license on the internet - -#include once - - -; --------------------------------------------------------------------- -; MEM_CALLOC -; Allocates a block of memory in the heap, and clears it filling it -; with 0 bytes -; -; Parameters -; BC = Length of requested memory block -; -; Returns: -; HL = Pointer to the allocated block in memory. Returns 0 (NULL) -; if the block could not be allocated (out of memory) -; --------------------------------------------------------------------- - push namespace core - -__MEM_CALLOC: - push bc - call __MEM_ALLOC - pop bc - ld a, h - or l - ret z ; No memory - ld (hl), 0 - dec bc - ld a, b - or c - ret z ; Already filled (1 byte-length block) - ld d, h - ld e, l - inc de - push hl - ldir - pop hl - ret +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/mem/free.asm b/src/lib/arch/zxnext/runtime/mem/free.asm index 171cbfa98..db5840847 100644 --- a/src/lib/arch/zxnext/runtime/mem/free.asm +++ b/src/lib/arch/zxnext/runtime/mem/free.asm @@ -1,193 +1,8 @@ -; vim: ts=4:et:sw=4: -; Copyleft (K) by Jose M. Rodriguez de la Rosa -; (a.k.a. Boriel) -; http://www.boriel.com +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; This ASM library is licensed under the BSD license -; you can use it for any purpose (even for commercial -; closed source programs). -; -; Please read the BSD license on the internet - -; ----- IMPLEMENTATION NOTES ------ -; The heap is implemented as a linked list of free blocks. - -; Each free block contains this info: -; -; +----------------+ <-- HEAP START -; | Size (2 bytes) | -; | 0 | <-- Size = 0 => DUMMY HEADER BLOCK -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ <-+ -; | Size (2 bytes) | -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ | -; | | | <-- If Size > 4, then this contains (size - 4) bytes -; | (0 if Size = 4)| | -; +----------------+ <-+ -; | Size (2 bytes) | -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ | -; | | | -; | (0 if Size = 4)| | -; +----------------+ | -; | <-- This zone is in use (Already allocated) -; +----------------+ <-+ -; | Size (2 bytes) | -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ | -; | | | -; | (0 if Size = 4)| | -; +----------------+ <-+ -; | Next (2 bytes) |--> NULL => END OF LIST -; | 0 = NULL | -; +----------------+ -; | | -; | (0 if Size = 4)| -; +----------------+ - - -; When a block is FREED, the previous and next pointers are examined to see -; if we can defragment the heap. If the block to be breed is just next to the -; previous, or to the next (or both) they will be converted into a single -; block (so defragmented). - - -; MEMORY MANAGER -; -; This library must be initialized calling __MEM_INIT with -; HL = BLOCK Start & DE = Length. - -; An init directive is useful for initialization routines. -; They will be added automatically if needed. - -#include once - -; --------------------------------------------------------------------- -; MEM_FREE -; Frees a block of memory -; -; Parameters: -; HL = Pointer to the block to be freed. If HL is NULL (0) nothing -; is done -; --------------------------------------------------------------------- - - push namespace core - -MEM_FREE: -__MEM_FREE: ; Frees the block pointed by HL - ; HL DE BC & AF modified - PROC - - LOCAL __MEM_LOOP2 - LOCAL __MEM_LINK_PREV - LOCAL __MEM_JOIN_TEST - LOCAL __MEM_BLOCK_JOIN - - ld a, h - or l - ret z ; Return if NULL pointer - - dec hl - dec hl - ld b, h - ld c, l ; BC = Block pointer - - ld hl, ZXBASIC_MEM_HEAP ; This label point to the heap start - -__MEM_LOOP2: - inc hl - inc hl ; Next block ptr - - ld e, (hl) - inc hl - ld d, (hl) ; Block next ptr - ex de, hl ; DE = &(block->next); HL = block->next - - ld a, h ; HL == NULL? - or l - jp z, __MEM_LINK_PREV; if so, link with previous - - or a ; Clear carry flag - sbc hl, bc ; Carry if BC > HL => This block if before - add hl, bc ; Restores HL, preserving Carry flag - jp c, __MEM_LOOP2 ; This block is before. Keep searching PASS the block - -;------ At this point current HL is PAST BC, so we must link (DE) with BC, and HL in BC->next - -__MEM_LINK_PREV: ; Link (DE) with BC, and BC->next with HL - ex de, hl - push hl - dec hl - - ld (hl), c - inc hl - ld (hl), b ; (DE) <- BC - - ld h, b ; HL <- BC (Free block ptr) - ld l, c - inc hl ; Skip block length (2 bytes) - inc hl - ld (hl), e ; Block->next = DE - inc hl - ld (hl), d - ; --- LINKED ; HL = &(BC->next) + 2 - - call __MEM_JOIN_TEST - pop hl - -__MEM_JOIN_TEST: ; Checks for fragmented contiguous blocks and joins them - ; hl = Ptr to current block + 2 - ld d, (hl) - dec hl - ld e, (hl) - dec hl - ld b, (hl) ; Loads block length into BC - dec hl - ld c, (hl) ; - - push hl ; Saves it for later - add hl, bc ; Adds its length. If HL == DE now, it must be joined - or a - sbc hl, de ; If Z, then HL == DE => We must join - pop hl - ret nz - -__MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed by DE). HL->length already in BC - push hl ; Saves it for later - ex de, hl - - ld e, (hl) ; DE -> block->next->length - inc hl - ld d, (hl) - inc hl - - ex de, hl ; DE = &(block->next) - add hl, bc ; HL = Total Length - - ld b, h - ld c, l ; BC = Total Length - - ex de, hl - ld e, (hl) - inc hl - ld d, (hl) ; DE = block->next - - pop hl ; Recovers Pointer to block - ld (hl), c - inc hl - ld (hl), b ; Length Saved - inc hl - ld (hl), e - inc hl - ld (hl), d ; Next saved - ret - - ENDP - - pop namespace +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/mem/heapinit.asm b/src/lib/arch/zxnext/runtime/mem/heapinit.asm index 7c09a1129..00e039d77 100644 --- a/src/lib/arch/zxnext/runtime/mem/heapinit.asm +++ b/src/lib/arch/zxnext/runtime/mem/heapinit.asm @@ -1,129 +1,8 @@ -; vim: ts=4:et:sw=4: -; Copyleft (K) by Jose M. Rodriguez de la Rosa -; (a.k.a. Boriel) -; http://www.boriel.com +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; This ASM library is licensed under the BSD license -; you can use it for any purpose (even for commercial -; closed source programs). -; -; Please read the BSD license on the internet - -; ----- IMPLEMENTATION NOTES ------ -; The heap is implemented as a linked list of free blocks. - -; Each free block contains this info: -; -; +----------------+ <-- HEAP START -; | Size (2 bytes) | -; | 0 | <-- Size = 0 => DUMMY HEADER BLOCK -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ <-+ -; | Size (2 bytes) | -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ | -; | | | <-- If Size > 4, then this contains (size - 4) bytes -; | (0 if Size = 4)| | -; +----------------+ <-+ -; | Size (2 bytes) | -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ | -; | | | -; | (0 if Size = 4)| | -; +----------------+ | -; | <-- This zone is in use (Already allocated) -; +----------------+ <-+ -; | Size (2 bytes) | -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ | -; | | | -; | (0 if Size = 4)| | -; +----------------+ <-+ -; | Next (2 bytes) |--> NULL => END OF LIST -; | 0 = NULL | -; +----------------+ -; | | -; | (0 if Size = 4)| -; +----------------+ - - -; When a block is FREED, the previous and next pointers are examined to see -; if we can defragment the heap. If the block to be breed is just next to the -; previous, or to the next (or both) they will be converted into a single -; block (so defragmented). - - -; MEMORY MANAGER -; -; This library must be initialized calling __MEM_INIT with -; HL = BLOCK Start & DE = Length. - -; An init directive is useful for initialization routines. -; They will be added automatically if needed. - -#init ".core.__MEM_INIT" - - -; --------------------------------------------------------------------- -; __MEM_INIT must be called to initalize this library with the -; standard parameters -; --------------------------------------------------------------------- - push namespace core - -__MEM_INIT: ; Initializes the library using (RAMTOP) as start, and - ld hl, ZXBASIC_MEM_HEAP ; Change this with other address of heap start - ld de, ZXBASIC_HEAP_SIZE ; Change this with your size - -; --------------------------------------------------------------------- -; __MEM_INIT2 initalizes this library -; Parameters: -; HL : Memory address of 1st byte of the memory heap -; DE : Length in bytes of the Memory Heap -; --------------------------------------------------------------------- -__MEM_INIT2: - ; HL as TOP - PROC - - dec de - dec de - dec de - dec de ; DE = length - 4; HL = start - ; This is done, because we require 4 bytes for the empty dummy-header block - - xor a - ld (hl), a - inc hl - ld (hl), a ; First "free" block is a header: size=0, Pointer=&(Block) + 4 - inc hl - - ld b, h - ld c, l - inc bc - inc bc ; BC = starts of next block - - ld (hl), c - inc hl - ld (hl), b - inc hl ; Pointer to next block - - ld (hl), e - inc hl - ld (hl), d - inc hl ; Block size (should be length - 4 at start); This block contains all the available memory - - ld (hl), a ; NULL (0000h) ; No more blocks (a list with a single block) - inc hl - ld (hl), a - - ld a, 201 - ld (__MEM_INIT), a; "Pokes" with a RET so ensure this routine is not called again - ret - - ENDP - - pop namespace +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/mem/memcopy.asm b/src/lib/arch/zxnext/runtime/mem/memcopy.asm index ab4816ea0..1cf2732b8 100644 --- a/src/lib/arch/zxnext/runtime/mem/memcopy.asm +++ b/src/lib/arch/zxnext/runtime/mem/memcopy.asm @@ -2,52 +2,7 @@ ; This file is released under the MIT License ; ; Copyleft (k) 2008 -; by Jose Rodriguez-Rosa (a.k.a. Boriel) -; -; Use this file as a template to develop your own library file +; by Jose Rodriguez-Rosa (a.k.a. Boriel) ; ---------------------------------------------------------------- -; Emulates both memmove and memcpy C routines -; Block will be safely copied if they overlap - -; HL => Start of source block -; DE => Start of destiny block -; BC => Block length - - push namespace core - -__MEMCPY: - - PROC - LOCAL __MEMCPY2 - - push hl - add hl, bc ; addr of last source block byte + 1 - or a - sbc hl, de ; checks if DE > HL + BC - pop hl ; recovers HL. If carry => DE > HL + BC (no overlap) - jr c, __MEMCPY2 - - ; Now checks if DE <= HL - - sbc hl, de ; Even if overlap, if DE < HL then we can LDIR safely - add hl, de - jr nc, __MEMCPY2 - - dec bc - add hl, bc - ex de, hl - add hl, bc - ex de, hl - inc bc ; HL and DE point to the last byte position - - lddr ; Copies from end to beginning - ret - -__MEMCPY2: - ldir - ret - - ENDP - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/mem/realloc.asm b/src/lib/arch/zxnext/runtime/mem/realloc.asm index 01e832fdb..23786a98d 100644 --- a/src/lib/arch/zxnext/runtime/mem/realloc.asm +++ b/src/lib/arch/zxnext/runtime/mem/realloc.asm @@ -1,160 +1,8 @@ -; vim: ts=4:et:sw=4: -; Copyleft (K) by Jose M. Rodriguez de la Rosa -; (a.k.a. Boriel) -; http://www.boriel.com +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; This ASM library is licensed under the BSD license -; you can use it for any purpose (even for commercial -; closed source programs). -; -; Please read the BSD license on the internet - -; ----- IMPLEMENTATION NOTES ------ -; The heap is implemented as a linked list of free blocks. - -; Each free block contains this info: -; -; +----------------+ <-- HEAP START -; | Size (2 bytes) | -; | 0 | <-- Size = 0 => DUMMY HEADER BLOCK -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ <-+ -; | Size (2 bytes) | -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ | -; | | | <-- If Size > 4, then this contains (size - 4) bytes -; | (0 if Size = 4)| | -; +----------------+ <-+ -; | Size (2 bytes) | -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ | -; | | | -; | (0 if Size = 4)| | -; +----------------+ | -; | <-- This zone is in use (Already allocated) -; +----------------+ <-+ -; | Size (2 bytes) | -; +----------------+ -; | Next (2 bytes) |---+ -; +----------------+ | -; | | | -; | (0 if Size = 4)| | -; +----------------+ <-+ -; | Next (2 bytes) |--> NULL => END OF LIST -; | 0 = NULL | -; +----------------+ -; | | -; | (0 if Size = 4)| -; +----------------+ - - -; When a block is FREED, the previous and next pointers are examined to see -; if we can defragment the heap. If the block to be breed is just next to the -; previous, or to the next (or both) they will be converted into a single -; block (so defragmented). - - -; MEMORY MANAGER -; -; This library must be initialized calling __MEM_INIT with -; HL = BLOCK Start & DE = Length. - -; An init directive is useful for initialization routines. -; They will be added automatically if needed. - - -#include once -#include once -#include once - - -; --------------------------------------------------------------------- -; MEM_REALLOC -; Reallocates a block of memory in the heap. -; -; Parameters -; HL = Pointer to the original block -; BC = New Length of requested memory block -; -; Returns: -; HL = Pointer to the allocated block in memory. Returns 0 (NULL) -; if the block could not be allocated (out of memory) -; -; Notes: -; If BC = 0, the block is freed, otherwise -; the content of the original block is copied to the new one, and -; the new size is adjusted. If BC < original length, the content -; will be truncated. Otherwise, extra block content might contain -; memory garbage. -; -; --------------------------------------------------------------------- - push namespace core - -__REALLOC: ; Reallocates block pointed by HL, with new length BC - PROC - - LOCAL __REALLOC_END - - ld a, h - or l - jp z, __MEM_ALLOC ; If HL == NULL, just do a malloc - - ld e, (hl) - inc hl - ld d, (hl) ; DE = First 2 bytes of HL block - - push hl - exx - pop de - inc de ; DE' <- HL + 2 - exx ; DE' <- HL (Saves current pointer into DE') - - dec hl ; HL = Block start - - push de - push bc - call __MEM_FREE ; Frees current block - pop bc - push bc - call __MEM_ALLOC ; Gets a new block of length BC - pop bc - pop de - - ld a, h - or l - ret z ; Return if HL == NULL (No memory) - - ld (hl), e - inc hl - ld (hl), d - inc hl ; Recovers first 2 bytes in HL - - dec bc - dec bc ; BC = BC - 2 (Two bytes copied) - - ld a, b - or c - jp z, __REALLOC_END ; Ret if nothing to copy (BC == 0) - - exx - push de - exx - pop de ; DE <- DE' ; Start of remaining block - - push hl ; Saves current Block + 2 start - ex de, hl ; Exchanges them: DE is destiny block - ldir ; Copies BC Bytes - pop hl ; Recovers Block + 2 start - -__REALLOC_END: - - dec hl ; Set HL - dec hl ; To begin of block - ret - - ENDP +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/neg16.asm b/src/lib/arch/zxnext/runtime/neg16.asm index b21f8ea92..5acf5a4f4 100644 --- a/src/lib/arch/zxnext/runtime/neg16.asm +++ b/src/lib/arch/zxnext/runtime/neg16.asm @@ -1,19 +1,8 @@ -; Negates HL value (16 bit) - push namespace core - -__ABS16: - bit 7, h - ret z - -__NEGHL: - ld a, l ; HL = -HL - cpl - ld l, a - ld a, h - cpl - ld h, a - inc hl - ret - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/neg32.asm b/src/lib/arch/zxnext/runtime/neg32.asm index ce7932ee4..216cad001 100644 --- a/src/lib/arch/zxnext/runtime/neg32.asm +++ b/src/lib/arch/zxnext/runtime/neg32.asm @@ -1,34 +1,8 @@ - push namespace core - -__ABS32: - bit 7, d - ret z - -__NEG32: ; Negates DEHL (Two's complement) - ld a, l - cpl - ld l, a - - ld a, h - cpl - ld h, a - - ld a, e - cpl - ld e, a - - ld a, d - cpl - ld d, a - - inc l - ret nz - - inc h - ret nz - - inc de - ret - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/negf.asm b/src/lib/arch/zxnext/runtime/negf.asm index b74adb6aa..9420c7020 100644 --- a/src/lib/arch/zxnext/runtime/negf.asm +++ b/src/lib/arch/zxnext/runtime/negf.asm @@ -1,29 +1,8 @@ -#include once -#include once -#include once - -; ------------------------------------------------------------- -; Floating point library using the FP ROM Calculator (ZX 48K) - -; All of them uses C EDHL registers as 1st paramter. -; For binary operators, the 2n operator must be pushed into the -; stack, in the order BC DE HL (B not used). +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Uses CALLEE convention -; ------------------------------------------------------------- - - push namespace core - -__NEGF: ; A = -A - call __FPSTACK_PUSH - - ; ------------- ROM NEGATE - rst 28h - defb 1Bh ; NEGF - defb 38h; ; END CALC - - jp __FPSTACK_POP - - pop namespace - +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/ongoto.asm b/src/lib/arch/zxnext/runtime/ongoto.asm index bf71c9c8f..aaf260f8d 100644 --- a/src/lib/arch/zxnext/runtime/ongoto.asm +++ b/src/lib/arch/zxnext/runtime/ongoto.asm @@ -1,35 +1,8 @@ -; ------------------------------------------------------ -; Implements ON .. GOTO -; ------------------------------------------------------ - - push namespace core - -__ON_GOSUB: - pop hl - ex (sp), hl ; hl = beginning of table - call __ON_GOTO_START - ret - -__ON_GOTO: - pop hl - ex (sp), hl ; hl = beginning of table - -__ON_GOTO_START: - ; hl = address of jump table - ; a = index (0..255) - cp (hl) ; length of last post - ret nc ; a >= length of last position (out of range) - inc hl - pop de ; removes ret addr from the stack - ld d, 0 - add a, a - ld e, a - rl d - add hl, de - ld a, (hl) - inc hl - ld h, (hl) - ld l, a - jp (hl) - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/over.asm b/src/lib/arch/zxnext/runtime/over.asm index afe15fc55..7bdb74273 100644 --- a/src/lib/arch/zxnext/runtime/over.asm +++ b/src/lib/arch/zxnext/runtime/over.asm @@ -1,49 +1,8 @@ -; Sets OVER flag in P_FLAG permanently -; Parameter: OVER flag in bit 0 of A register -#include once -#include once - - push namespace core - -OVER: - PROC - - ld c, a ; saves it for later - and 2 - ld hl, FLAGS2 - res 1, (HL) - or (hl) - ld (hl), a - - ld a, c ; Recovers previous value - and 1 ; # Convert to 0/1 - add a, a; # Shift left 1 bit for permanent - - ld hl, P_FLAG - res 1, (hl) - or (hl) - ld (hl), a - ret - -; Sets OVER flag in P_FLAG temporarily -OVER_TMP: - ld c, a ; saves it for later - and 2 ; gets bit 1; clears carry - rra - ld hl, FLAGS2 - res 0, (hl) - or (hl) - ld (hl), a - - ld a, c ; Recovers previous value - and 1 - ld hl, P_FLAG - res 0, (hl) - or (hl) - ld (hl), a - jp __SET_ATTR_MODE - - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/paper.asm b/src/lib/arch/zxnext/runtime/paper.asm index 55c9600ba..c8b6cce98 100644 --- a/src/lib/arch/zxnext/runtime/paper.asm +++ b/src/lib/arch/zxnext/runtime/paper.asm @@ -1,50 +1,8 @@ -; Sets paper color in ATTR_P permanently -; Parameter: Paper color in A register - -#include once - - push namespace core - -PAPER: - PROC - LOCAL __SET_PAPER - LOCAL __SET_PAPER2 - - ld de, ATTR_P - -__SET_PAPER: - cp 8 - jr nz, __SET_PAPER2 - inc de - ld a, (de) - or 038h - ld (de), a - ret - - ; Another entry. This will set the paper color at location pointer by DE -__SET_PAPER2: - and 7 ; # Remove - rlca - rlca - rlca ; a *= 8 - - ld b, a ; Saves the color - ld a, (de) - and 0C7h ; Clears previous value - or b - ld (de), a - inc de ; Points to MASK_T or MASK_P accordingly - ld a, (de) - and 0C7h ; Resets bits 3,4,5 - ld (de), a - ret - - -; Sets the PAPER color passed in A register in the ATTR_T variable -PAPER_TMP: - ld de, ATTR_T - jp __SET_PAPER - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/pause.asm b/src/lib/arch/zxnext/runtime/pause.asm index b07fb3976..a7624dcb3 100644 --- a/src/lib/arch/zxnext/runtime/pause.asm +++ b/src/lib/arch/zxnext/runtime/pause.asm @@ -1,10 +1,8 @@ -; The PAUSE statement (Calling the ROM) +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - push namespace core - -__PAUSE: - ld b, h - ld c, l - jp 1F3Dh ; PAUSE_1 - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/pistore32.asm b/src/lib/arch/zxnext/runtime/pistore32.asm index 49418d113..58463ff90 100644 --- a/src/lib/arch/zxnext/runtime/pistore32.asm +++ b/src/lib/arch/zxnext/runtime/pistore32.asm @@ -1,3 +1,8 @@ -#include once +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -; The content of this file has been moved to "store32.asm" +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/ploadf.asm b/src/lib/arch/zxnext/runtime/ploadf.asm index cba7b7b0a..cf46d75dd 100644 --- a/src/lib/arch/zxnext/runtime/ploadf.asm +++ b/src/lib/arch/zxnext/runtime/ploadf.asm @@ -1,17 +1,8 @@ -; Parameter / Local var load -; A => Offset -; IX = Stack Frame -; RESULT: HL => IX + DE - -#include once - - push namespace core - -__PLOADF: - push ix - pop hl - add hl, de - jp __LOADF - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/plot.asm b/src/lib/arch/zxnext/runtime/plot.asm index 869e85e80..4fa0674f8 100644 --- a/src/lib/arch/zxnext/runtime/plot.asm +++ b/src/lib/arch/zxnext/runtime/plot.asm @@ -1,92 +1,8 @@ -; MIXED __FASTCAL__ / __CALLE__ PLOT Function -; Plots a point into the screen calling the ZX ROM PLOT routine - -; Y in A (accumulator) -; X in top of the stack - -#include once -#include once -#include once -#include once - - push namespace core - -PLOT: - PROC - - LOCAL PLOT_SUB - LOCAL PIXEL_ADDR - LOCAL COORDS - LOCAL __PLOT_ERR - LOCAL P_FLAG - LOCAL __PLOT_OVER1 - -P_FLAG EQU 23697 - - pop hl - ex (sp), hl ; Callee - - ld b, a - ld c, h - -#ifdef SCREEN_Y_OFFSET - ld a, SCREEN_Y_OFFSET - add a, b - ld b, a -#endif - -#ifdef SCREEN_X_OFFSET - ld a, SCREEN_X_OFFSET - add a, c - ld c, a -#endif - - ld a, 191 - cp b - jr c, __PLOT_ERR ; jr is faster here (#1) - -__PLOT: ; __FASTCALL__ entry (b, c) = pixel coords (y, x) - ld (COORDS), bc ; Saves current point - ld a, 191 ; Max y coord - call PIXEL_ADDR - res 6, h ; Starts from 0 - ld bc, (SCREEN_ADDR) - add hl, bc ; Now current offset - - ld b, a - inc b - ld a, 0FEh -LOCAL __PLOT_LOOP -__PLOT_LOOP: - rrca - djnz __PLOT_LOOP - - ld b, a - ld a, (P_FLAG) - ld c, a - ld a, (hl) - bit 0, c ; is it OVER 1 - jr nz, __PLOT_OVER1 - and b - -__PLOT_OVER1: - bit 2, c ; is it inverse 1 - jr nz, __PLOT_END - - xor b - cpl - -LOCAL __PLOT_END -__PLOT_END: - ld (hl), a - jp SET_PIXEL_ADDR_ATTR - -__PLOT_ERR: - jp __OUT_OF_SCREEN_ERR ; Spent 3 bytes, but saves 3 T-States at (#1) - -PLOT_SUB EQU 22ECh -PIXEL_ADDR EQU 22ACh -COORDS EQU 5C7Dh - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/print.asm b/src/lib/arch/zxnext/runtime/print.asm index c60ec5d47..0aabb3d55 100644 --- a/src/lib/arch/zxnext/runtime/print.asm +++ b/src/lib/arch/zxnext/runtime/print.asm @@ -1,583 +1,8 @@ -; vim:ts=4:sw=4:et: -; PRINT command routine -; Does not print attribute. Use PRINT_STR or PRINT_NUM for that - -#include once -#include once -#include once -#include once -#include once -#include once -#include once -#include once -#include once -#include once -#include once -#include once -#include once - -; Putting a comment starting with @INIT
-; will make the compiler to add a CALL to
-; It is useful for initialization routines. -#init .core.__PRINT_INIT - - push namespace core - -__PRINT_INIT: ; To be called before program starts (initializes library) - PROC - - ld hl, __PRINT_START - ld (PRINT_JUMP_STATE), hl - - ;; Clears ATTR2 flags (OVER 2, etc) - xor a - ld (FLAGS2), a - ld hl, TV_FLAG - res 0, (hl) - - LOCAL SET_SCR_ADDR - call __LOAD_S_POSN - jp __SET_SCR_PTR - - ;; Receives HL = future value of S_POSN - ;; Stores it at (S_POSN) and refresh screen pointers (ATTR, SCR) -SET_SCR_ADDR: - ld (S_POSN), hl - ex de, hl - ld hl, SCR_SIZE - or a - sbc hl, de - ex de, hl - dec e - jp __SET_SCR_PTR - -__PRINTCHAR: ; Print character store in accumulator (A register) - ; Modifies H'L', B'C', A'F', D'E', A - - LOCAL PO_GR_1 - - LOCAL __PRCHAR - LOCAL __PRINT_JUMP - LOCAL __SRCADDR - LOCAL __PRINT_UDG - LOCAL __PRGRAPH - LOCAL __PRINT_START - -PRINT_JUMP_STATE EQU __PRINT_JUMP + 2 - -__PRINT_JUMP: - exx ; Switch to alternative registers - jp __PRINT_START ; Where to jump. If we print 22 (AT), next two calls jumps to AT1 and AT2 respectively - -__PRINT_START: - -__PRINT_CHR: - cp ' ' - jr c, __PRINT_SPECIAL ; Characters below ' ' are special ones - ex af, af' ; Saves a value (char to print) for later - - ld hl, (S_POSN) - dec l - jr nz, 1f - ld l, SCR_COLS - 1 - dec h - jr nz, 2f - -#ifndef __ZXB_DISABLE_SCROLL - inc h - push hl - call __SCROLL_SCR - pop hl -#else - ld h, SCR_ROWS - 1 -#endif -2: - call SET_SCR_ADDR - jr 4f -1: - ld (S_POSN), hl -4: - ex af, af' - - cp 80h ; Is it a "normal" (printable) char - jr c, __SRCADDR - - cp 90h ; Is it an UDG? - jr nc, __PRINT_UDG - - ; Print an 8 bit pattern (80h to 8Fh) - - ld b, a - call PO_GR_1 ; This ROM routine will generate the bit pattern at MEM0 - ld hl, MEM0 - jp __PRGRAPH - -PO_GR_1 EQU 0B38h - -__PRINT_UDG: - sub 90h ; Sub ASC code - ld bc, (UDG) - jr __PRGRAPH0 - -__SOURCEADDR EQU (__SRCADDR + 1) ; Address of the pointer to chars source -__SRCADDR: - ld bc, (CHARS) - -__PRGRAPH0: - add a, a ; A = a * 2 (since a < 80h) ; Thanks to Metalbrain at http://foro.speccy.org - ld l, a - ld h, 0 ; HL = a * 2 (accumulator) - add hl, hl - add hl, hl ; HL = a * 8 - add hl, bc ; HL = CHARS address - -__PRGRAPH: - ex de, hl ; HL = Write Address, DE = CHARS address - -#ifndef __ZXB_DISABLE_BOLD - bit 2, (iy + $47) - call nz, __BOLD -#endif - -#ifndef __ZXB_DISABLE_ITALIC - bit 4, (iy + $47) - call nz, __ITALIC -#endif - - ld hl, (DFCC) - push hl - - ld b, 8 ; 8 bytes per char - -__PRCHAR: - ld a, (de) ; DE *must* be source, and HL destiny - -PRINT_MODE: ; Which operation is used to write on the screen - ; Set it with: - ; LD A, - ; LD (PRINT_MODE), A - ; - ; Available operations: - ; NORMAL : 0h --> NOP ; OVER 0 - ; XOR : AEh --> XOR (HL) ; OVER 1 - ; OR : B6h --> OR (HL) ; PUTSPRITE - ; AND : A6h --> AND (HL) ; PUTMASK - nop ; Set to one of the values above - -INVERSE_MODE: ; 00 -> NOP -> INVERSE 0 - nop ; 2F -> CPL -> INVERSE 1 - - ld (hl), a - - inc de - inc h ; Next line - djnz __PRCHAR - - pop hl - inc hl - ld (DFCC), hl - - ld hl, (DFCCL) ; current ATTR Pos - inc hl - ld (DFCCL), hl - dec hl - call __SET_ATTR - exx - ret - -; ------------- SPECIAL CHARS (< 32) ----------------- - -__PRINT_SPECIAL: ; Jumps here if it is a special char - ld hl, __PRINT_TABLE - jp JUMP_HL_PLUS_2A - -PRINT_EOL: ; Called WHENEVER there is no ";" at end of PRINT sentence - exx - -__PRINT_0Dh: ; Called WHEN printing CHR$(13) - ld hl, (S_POSN) - dec l - jr nz, 1f - dec h - jr nz, 1f -#ifndef __ZXB_DISABLE_SCROLL - inc h - push hl - call __SCROLL_SCR - pop hl -#else - ld h, SCR_ROWS - 1 -#endif -1: - ld l, 1 - -__PRINT_EOL_END: - call SET_SCR_ADDR - exx - ret - -__PRINT_COM: - exx - push hl - push de - push bc - call PRINT_COMMA - pop bc - pop de - pop hl - ret - -__PRINT_TAB: - ld hl, __PRINT_TAB1 - jr __PRINT_SET_STATE - -__PRINT_TAB1: - ld (MEM0), a - ld hl, __PRINT_TAB2 - jr __PRINT_SET_STATE - -__PRINT_TAB2: - ld a, (MEM0) ; Load tab code (ignore the current one) - ld hl, __PRINT_START - ld (PRINT_JUMP_STATE), hl - exx - push hl - push bc - push de - call PRINT_TAB - pop de - pop bc - pop hl - ret - -__PRINT_AT: - ld hl, __PRINT_AT1 - jr __PRINT_SET_STATE - -__PRINT_NOP: -__PRINT_RESTART: - ld hl, __PRINT_START - -__PRINT_SET_STATE: - ld (PRINT_JUMP_STATE), hl ; Saves next entry call - exx - ret - -__PRINT_AT1: ; Jumps here if waiting for 1st parameter - ld hl, (S_POSN) - ld h, a - ld a, SCR_ROWS - sub h - ld (S_POSN + 1), a - - ld hl, __PRINT_AT2 - jr __PRINT_SET_STATE - -__PRINT_AT2: - call __LOAD_S_POSN - ld e, a - call __SAVE_S_POSN - jr __PRINT_RESTART - -__PRINT_DEL: - call __LOAD_S_POSN ; Gets current screen position - dec e - ld a, -1 - cp e - jr nz, 3f - ld e, SCR_COLS - 2 - dec d - cp d - jr nz, 3f - ld d, SCR_ROWS - 1 -3: - call __SAVE_S_POSN - exx - ret - -__PRINT_INK: - ld hl, __PRINT_INK2 - jr __PRINT_SET_STATE - -__PRINT_INK2: - call INK_TMP - jr __PRINT_RESTART - -__PRINT_PAP: - ld hl, __PRINT_PAP2 - jr __PRINT_SET_STATE - -__PRINT_PAP2: - call PAPER_TMP - jr __PRINT_RESTART - -__PRINT_FLA: - ld hl, __PRINT_FLA2 - jr __PRINT_SET_STATE - -__PRINT_FLA2: - call FLASH_TMP - jr __PRINT_RESTART - -__PRINT_BRI: - ld hl, __PRINT_BRI2 - jr __PRINT_SET_STATE - -__PRINT_BRI2: - call BRIGHT_TMP - jr __PRINT_RESTART - -__PRINT_INV: - ld hl, __PRINT_INV2 - jr __PRINT_SET_STATE - -__PRINT_INV2: - call INVERSE_TMP - jr __PRINT_RESTART - -__PRINT_OVR: - ld hl, __PRINT_OVR2 - jr __PRINT_SET_STATE - -__PRINT_OVR2: - call OVER_TMP - jr __PRINT_RESTART - -#ifndef __ZXB_DISABLE_BOLD -__PRINT_BOLD: - ld hl, __PRINT_BOLD2 - jp __PRINT_SET_STATE - -__PRINT_BOLD2: - call BOLD_TMP - jp __PRINT_RESTART -#endif - -#ifndef __ZXB_DISABLE_ITALIC -__PRINT_ITA: - ld hl, __PRINT_ITA2 - jp __PRINT_SET_STATE - -__PRINT_ITA2: - call ITALIC_TMP - jp __PRINT_RESTART -#endif - -#ifndef __ZXB_DISABLE_BOLD - LOCAL __BOLD - -__BOLD: - push hl - ld hl, MEM0 - ld b, 8 -1: - ld a, (de) - ld c, a - rlca - or c - ld (hl), a - inc hl - inc de - djnz 1b - pop hl - ld de, MEM0 - ret -#endif - -#ifndef __ZXB_DISABLE_ITALIC - LOCAL __ITALIC - -__ITALIC: - push hl - ld hl, MEM0 - ex de, hl - ld bc, 8 - ldir - ld hl, MEM0 - srl (hl) - inc hl - srl (hl) - inc hl - srl (hl) - inc hl - inc hl - inc hl - sla (hl) - inc hl - sla (hl) - inc hl - sla (hl) - pop hl - ld de, MEM0 - ret -#endif - -#ifndef __ZXB_DISABLE_SCROLL - LOCAL __SCROLL_SCR - -# ifdef __ZXB_ENABLE_BUFFER_SCROLL -__SCROLL_SCR: ;; Scrolls screen and attrs 1 row up - ld de, (SCREEN_ADDR) - ld b, 3 -3: - push bc - ld a, 8 -1: - ld hl, 32 - add hl, de - ld bc, 32 * 7 - push de - ldir - pop de - inc d - dec a - jr nz, 1b - push hl - ld bc, -32 - 256 * 7 - add hl, bc - ex de, hl - ld a, 8 -2: - ld bc, 32 - push hl - push de - ldir - pop de - pop hl - inc d - inc h - dec a - jr nz, 2b - pop de - pop bc - djnz 3b - - dec de - ld h, d - ld l, e - ld a, 8 -3: - push hl - push de - ld (hl), b - dec de - ld bc, 31 - lddr - pop de - pop hl - dec d - dec h - dec a - jr nz, 3b - - ld de, (SCREEN_ATTR_ADDR) - ld hl, 32 - add hl, de - ld bc, 32 * 23 - ldir - - ld h, d - ld l, e - ld a, (ATTR_P) - ld (hl), a - inc de - ld bc, 31 - ldir - ret -# else -__SCROLL_SCR EQU 0DFEh ; Use ROM SCROLL -# endif -#endif - - -PRINT_COMMA: - call __LOAD_S_POSN - ld a, e - and 16 - add a, 16 - -PRINT_TAB: - ; Tabulates the number of spaces in A register - ; If the current cursor position is already A, does nothing - PROC - LOCAL LOOP - - call __LOAD_S_POSN ; e = current row - sub e - and 31 - ret z - - ld b, a -LOOP: - ld a, ' ' - call __PRINTCHAR - djnz LOOP - ret - ENDP - -PRINT_AT: ; Changes cursor to ROW, COL - ; COL in A register - ; ROW in stack - - pop hl ; Ret address - ex (sp), hl ; callee H = ROW - ld l, a - ex de, hl - - call __IN_SCREEN - ret nc ; Return if out of screen - jp __SAVE_S_POSN - - LOCAL __PRINT_COM - LOCAL __PRINT_AT1 - LOCAL __PRINT_AT2 - LOCAL __PRINT_BOLD - LOCAL __PRINT_ITA - LOCAL __PRINT_INK - LOCAL __PRINT_PAP - LOCAL __PRINT_SET_STATE - LOCAL __PRINT_TABLE - LOCAL __PRINT_TAB, __PRINT_TAB1, __PRINT_TAB2 - -#ifndef __ZXB_DISABLE_ITALIC - LOCAL __PRINT_ITA2 -#else - __PRINT_ITA EQU __PRINT_NOP -#endif - -#ifndef __ZXB_DISABLE_BOLD - LOCAL __PRINT_BOLD2 -#else - __PRINT_BOLD EQU __PRINT_NOP -#endif - -__PRINT_TABLE: ; Jump table for 0 .. 22 codes - - DW __PRINT_NOP ; 0 - DW __PRINT_NOP ; 1 - DW __PRINT_NOP ; 2 - DW __PRINT_NOP ; 3 - DW __PRINT_NOP ; 4 - DW __PRINT_NOP ; 5 - DW __PRINT_COM ; 6 COMMA - DW __PRINT_NOP ; 7 - DW __PRINT_DEL ; 8 DEL - DW __PRINT_NOP ; 9 - DW __PRINT_NOP ; 10 - DW __PRINT_NOP ; 11 - DW __PRINT_NOP ; 12 - DW __PRINT_0Dh ; 13 - DW __PRINT_BOLD ; 14 - DW __PRINT_ITA ; 15 - DW __PRINT_INK ; 16 - DW __PRINT_PAP ; 17 - DW __PRINT_FLA ; 18 - DW __PRINT_BRI ; 19 - DW __PRINT_INV ; 20 - DW __PRINT_OVR ; 21 - DW __PRINT_AT ; 22 AT - DW __PRINT_TAB ; 23 TAB - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/print_eol_attr.asm b/src/lib/arch/zxnext/runtime/print_eol_attr.asm index 6d4e25a2e..9cd40a8d9 100644 --- a/src/lib/arch/zxnext/runtime/print_eol_attr.asm +++ b/src/lib/arch/zxnext/runtime/print_eol_attr.asm @@ -1,13 +1,8 @@ -; Calls PRINT_EOL and then COPY_ATTR, so saves -; 3 bytes - -#include once -#include once - - push namespace core - -PRINT_EOL_ATTR: - call PRINT_EOL - jp COPY_ATTR - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/printf.asm b/src/lib/arch/zxnext/runtime/printf.asm index 73c713f09..2a36acd80 100644 --- a/src/lib/arch/zxnext/runtime/printf.asm +++ b/src/lib/arch/zxnext/runtime/printf.asm @@ -1,47 +1,8 @@ -#include once -#include once -#include once - - push namespace core - -__PRINTF: ; Prints a Fixed point Number stored in C ED LH - PROC - - LOCAL RECLAIM2 - LOCAL STK_END -STK_END EQU 5C65h - - ld hl, (ATTR_T) - push hl ; Saves ATTR_T since BUG ROM changes it - - ld hl, (STK_END) - push hl ; Stores STK_END - - call __FPSTACK_PUSH ; Push number into stack - rst 28h ; # Rom Calculator - defb 2Eh ; # STR$(x) - defb 38h ; # END CALC - call __FPSTACK_POP ; Recovers string parameters to A ED CB - - pop hl - ld (STK_END), hl ; Balance STK_END to avoid STR$ bug - - pop hl - ld (ATTR_T), hl ; Restores ATTR_T - - ex de, hl ; String position now in HL - - push bc - xor a ; Avoid the str to be FREED from heap - call __PRINT_STR - pop bc - inc bc - - jp RECLAIM2 ; Frees TMP Memory - -RECLAIM2 EQU 19E8h - - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/printf16.asm b/src/lib/arch/zxnext/runtime/printf16.asm index e5b4e8f2c..47ac20207 100644 --- a/src/lib/arch/zxnext/runtime/printf16.asm +++ b/src/lib/arch/zxnext/runtime/printf16.asm @@ -1,61 +1,8 @@ -#include once -#include once -#include once - - push namespace core - -__PRINTF16: ; Prints a 32bit 16.16 fixed point number - PROC - - LOCAL __PRINT_FIX_LOOP - LOCAL __PRINTF16_2 - - bit 7, d - jr z, __PRINTF16_2 - call __NEG32 - call __PRINT_MINUS - -__PRINTF16_2: - push hl - ex de, hl - call __PRINTU16 ; Prints integer part - pop hl - - ld a, h - or l - ret z ; Returns if integer - - push hl - ld a, '.' - call __PRINT_DIGIT ; Prints decimal point - pop hl - -__PRINT_FIX_LOOP: - ld a, h - or l - ret z ; Returns if no more decimals - - xor a - ld d, h - ld e, l - ; Fast NUM * 10 multiplication - add hl, hl ; - adc a, a ; AHL = AHL * 2 (= X * 2) - add hl, hl ; - adc a, a ; AHL = AHL * 2 (= X * 4) - - add hl, de ; - adc a, 0 ; AHL = AHL + DE (= X * 5) - add hl, hl - adc a, a ; AHL = AHL * 2 (= X * 10) - - push hl - or '0' - call __PRINT_DIGIT - pop hl - jp __PRINT_FIX_LOOP - - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/printi16.asm b/src/lib/arch/zxnext/runtime/printi16.asm index d44b22cbf..d884d3031 100644 --- a/src/lib/arch/zxnext/runtime/printi16.asm +++ b/src/lib/arch/zxnext/runtime/printi16.asm @@ -1,42 +1,8 @@ -#include once -#include once -#include once -#include once - - push namespace core - -__PRINTI16: ; Prints a 16bits signed in HL - ; Converts 16 to 32 bits - PROC - - LOCAL __PRINTU_LOOP - ld a, h - or a - - jp p, __PRINTU16 - - call __PRINT_MINUS - call __NEGHL - -__PRINTU16: - - ld b, 0 -__PRINTU_LOOP: - ld a, h - or l - jp z, __PRINTU_START - - push bc - ld de, 10 - call __DIVU16_FAST ; Divides by DE. DE = MODULUS at exit. Since < 256, E = Modulus - pop bc - - ld a, e - or '0' ; Stores ASCII digit (must be print in reversed order) - push af - inc b - jp __PRINTU_LOOP ; Uses JP in loops - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/printi32.asm b/src/lib/arch/zxnext/runtime/printi32.asm index eba8e215a..5fe1e6937 100644 --- a/src/lib/arch/zxnext/runtime/printi32.asm +++ b/src/lib/arch/zxnext/runtime/printi32.asm @@ -1,50 +1,8 @@ -#include once -#include once -#include once -#include once - - - push namespace core - -__PRINTI32: - ld a, d - or a - jp p, __PRINTU32 - - call __PRINT_MINUS - call __NEG32 - -__PRINTU32: - PROC - LOCAL __PRINTU_LOOP - - ld b, 0 ; Counter - -__PRINTU_LOOP: - ld a, h - or l - or d - or e - jp z, __PRINTU_START - - push bc - - ld bc, 0 - push bc - ld bc, 10 - push bc ; Push 00 0A (10 Dec) into the stack = divisor - - call __DIVU32 ; Divides by 32. D'E'H'L' contains modulo (L' since < 10) - pop bc - - exx - ld a, l - or '0' ; Stores ASCII digit (must be print in reversed order) - push af - exx - inc b - jp __PRINTU_LOOP ; Uses JP in loops - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/printi8.asm b/src/lib/arch/zxnext/runtime/printi8.asm index a12ecbfad..b95f74e53 100644 --- a/src/lib/arch/zxnext/runtime/printi8.asm +++ b/src/lib/arch/zxnext/runtime/printi8.asm @@ -1,41 +1,8 @@ -#include once -#include once - - push namespace core - -__PRINTI8: ; Prints an 8 bits number in Accumulator (A) - ; Converts 8 to 32 bits - or a - jp p, __PRINTU8 - - push af - call __PRINT_MINUS - pop af - neg - -__PRINTU8: - PROC - - LOCAL __PRINTU_LOOP - - ld b, 0 ; Counter - -__PRINTU_LOOP: - or a - jp z, __PRINTU_START - - push bc - ld h, 10 - call __DIVU8_FAST ; Divides by 10. D'E'H'L' contains modulo (L' since < 10) - pop bc - - ld a, l - or '0' ; Stores ASCII digit (must be print in reversed order) - push af - ld a, h - inc b - jp __PRINTU_LOOP ; Uses JP in loops - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/printnum.asm b/src/lib/arch/zxnext/runtime/printnum.asm index 28e4e98fe..c465f8039 100644 --- a/src/lib/arch/zxnext/runtime/printnum.asm +++ b/src/lib/arch/zxnext/runtime/printnum.asm @@ -1,36 +1,8 @@ -#include once -#include once - - push namespace core - -__PRINTU_START: - PROC - - LOCAL __PRINTU_CONT - - ld a, b - or a - jp nz, __PRINTU_CONT - - ld a, '0' - jp __PRINT_DIGIT - - -__PRINTU_CONT: - pop af - push bc - call __PRINT_DIGIT - pop bc - djnz __PRINTU_CONT - ret - - ENDP - - -__PRINT_MINUS: ; PRINT the MINUS (-) sign. CALLER must preserve registers - ld a, '-' - jp __PRINT_DIGIT - -__PRINT_DIGIT EQU __PRINTCHAR ; PRINTS the char in A register, and puts its attrs - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/printstr.asm b/src/lib/arch/zxnext/runtime/printstr.asm index 808e31878..20ff96df2 100644 --- a/src/lib/arch/zxnext/runtime/printstr.asm +++ b/src/lib/arch/zxnext/runtime/printstr.asm @@ -1,59 +1,8 @@ -#include once -#include once -#include once -#include once - -; PRINT command routine -; Prints string pointed by HL - - push namespace core - -PRINT_STR: -__PRINTSTR: ; __FASTCALL__ Entry to print_string - PROC - LOCAL __PRINT_STR_LOOP - LOCAL __PRINT_STR_END - - ld d, a ; Saves A reg (Flag) for later - - ld a, h - or l - ret z ; Return if the pointer is NULL - - push hl - - ld c, (hl) - inc hl - ld b, (hl) - inc hl ; BC = LEN(a$); HL = &a$ - -__PRINT_STR_LOOP: - ld a, b - or c - jr z, __PRINT_STR_END ; END if BC (counter = 0) - - ld a, (hl) - call __PRINTCHAR - inc hl - dec bc - jp __PRINT_STR_LOOP - -__PRINT_STR_END: - pop hl - ld a, d ; Recovers A flag - or a ; If not 0 this is a temporary string. Free it - ret z - jp __MEM_FREE ; Frees str from heap and return from there - -__PRINT_STR: - ; Fastcall Entry - ; It ONLY prints strings - ; HL = String start - ; BC = String length (Number of chars) - push hl ; Push str address for later - ld d, a ; Saves a FLAG - jp __PRINT_STR_LOOP - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/printu16.asm b/src/lib/arch/zxnext/runtime/printu16.asm index 1b62d6617..546dabdac 100644 --- a/src/lib/arch/zxnext/runtime/printu16.asm +++ b/src/lib/arch/zxnext/runtime/printu16.asm @@ -1,2 +1,8 @@ -#include once +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/printu32.asm b/src/lib/arch/zxnext/runtime/printu32.asm index 4114ac5cc..3d60d748e 100644 --- a/src/lib/arch/zxnext/runtime/printu32.asm +++ b/src/lib/arch/zxnext/runtime/printu32.asm @@ -1,2 +1,8 @@ -#include once +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/printu8.asm b/src/lib/arch/zxnext/runtime/printu8.asm index 77cc7c03c..fe3f865d7 100644 --- a/src/lib/arch/zxnext/runtime/printu8.asm +++ b/src/lib/arch/zxnext/runtime/printu8.asm @@ -1,2 +1,8 @@ -#include once +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/pstore32.asm b/src/lib/arch/zxnext/runtime/pstore32.asm index aac91082b..1bb80284f 100644 --- a/src/lib/arch/zxnext/runtime/pstore32.asm +++ b/src/lib/arch/zxnext/runtime/pstore32.asm @@ -1,14 +1,8 @@ -#include once +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -; Stores a 32 bit integer number (DE,HL) at (IX + BC) - push namespace core - -__PSTORE32: - push hl - push ix - pop hl - add hl, bc - pop bc - jp __STORE32 - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/pstoref.asm b/src/lib/arch/zxnext/runtime/pstoref.asm index c387b5547..e113ee1ba 100644 --- a/src/lib/arch/zxnext/runtime/pstoref.asm +++ b/src/lib/arch/zxnext/runtime/pstoref.asm @@ -1,21 +1,8 @@ -; Stores FP number in A ED CB at location HL+IX -; HL = Offset -; IX = Stack Frame -; A ED CB = FP Number - -#include once - -; Stored a float number in A ED CB into the address pointed by IX + HL - push namespace core - -__PSTOREF: - push de - ex de, hl ; DE <- HL - push ix - pop hl ; HL <- IX - add hl, de ; HL <- IX + DE - pop de - jp __STOREF - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/pstorestr.asm b/src/lib/arch/zxnext/runtime/pstorestr.asm index e65d1e340..7eee7b67e 100644 --- a/src/lib/arch/zxnext/runtime/pstorestr.asm +++ b/src/lib/arch/zxnext/runtime/pstorestr.asm @@ -1,18 +1,8 @@ -; vim:ts=4:et:sw=4 +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Stores an string (pointer to the HEAP by DE) into the address pointed -; by (IX + BC). A new copy of the string is created into the HEAP -; - -#include once - - push namespace core - -__PSTORE_STR: - push ix - pop hl - add hl, bc - jp __STORE_STR - - pop namespace +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/pstorestr2.asm b/src/lib/arch/zxnext/runtime/pstorestr2.asm index 85109c3b3..eee4c276c 100644 --- a/src/lib/arch/zxnext/runtime/pstorestr2.asm +++ b/src/lib/arch/zxnext/runtime/pstorestr2.asm @@ -1,19 +1,8 @@ -; vim:ts=4:et:sw=4 +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; Stores an string (pointer to the HEAP by DE) into the address pointed -; by (IX + BC). No new copy of the string is created into the HEAP, since -; it's supposed it's already created (temporary string) -; - -#include once - - push namespace core - -__PSTORE_STR2: - push ix - pop hl - add hl, bc - jp __STORE_STR2 - - pop namespace +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/pushf.asm b/src/lib/arch/zxnext/runtime/pushf.asm index d8a76c5ec..d910fe473 100644 --- a/src/lib/arch/zxnext/runtime/pushf.asm +++ b/src/lib/arch/zxnext/runtime/pushf.asm @@ -1,32 +1,8 @@ - -; Routine to push Float pointed by HL -; Into the stack. Notice that the hl points to the last -; byte of the FP number. -; Uses H'L' B'C' and D'E' to preserve ABCDEHL registers - - push namespace core - -__FP_PUSH_REV: - push hl - exx - pop hl - pop bc ; Return Address - ld d, (hl) - dec hl - ld e, (hl) - dec hl - push de - ld d, (hl) - dec hl - ld e, (hl) - dec hl - push de - ld d, (hl) - push de - push bc ; Return Address - exx - ret - - pop namespace - - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/random.asm b/src/lib/arch/zxnext/runtime/random.asm index 0e80a4b04..da9d274ed 100644 --- a/src/lib/arch/zxnext/runtime/random.asm +++ b/src/lib/arch/zxnext/runtime/random.asm @@ -1,109 +1,8 @@ -; RANDOM functions - - push namespace core - -RANDOMIZE: - ; Randomize with 32 bit seed in DE HL - ; if SEED = 0, calls ROM to take frames as seed - PROC - - LOCAL TAKE_FRAMES - LOCAL FRAMES - - ld a, h - or l - or d - or e - jr z, TAKE_FRAMES - - ld (RANDOM_SEED_LOW), hl - ld (RANDOM_SEED_HIGH), de - ret - -TAKE_FRAMES: - ; Takes the seed from frames - ld hl, (FRAMES) - ld (RANDOM_SEED_LOW), hl - ld hl, (FRAMES + 2) - ld (RANDOM_SEED_HIGH), hl - ret - -FRAMES EQU 23672 - ENDP - -RANDOM_SEED_HIGH EQU RAND+1 ; RANDOM seed, 16 higher bits -RANDOM_SEED_LOW EQU 23670 ; RANDOM seed, 16 lower bits - - -RAND: - PROC - ld de,0C0DEh ; yw -> zt - ld hl,(RANDOM_SEED_LOW) ; xz -> yw - ld (RANDOM_SEED_LOW),de ; x = y, z = w - ld a,e ; w = w ^ ( w << 3 ) - add a,a - add a,a - add a,a - xor e - ld e,a - ld a,h ; t = x ^ (x << 1) - add a,a - xor h - ld d,a - rra ; t = t ^ (t >> 1) ^ w - xor d - xor e - ld d,l ; y = z - ld e,a ; w = t - ld (RANDOM_SEED_HIGH),de - ret - ENDP - -RND: - ; Returns a FLOATING point integer - ; using RAND as a mantissa - PROC - LOCAL RND_LOOP - - call RAND - ; BC = HL since ZX BASIC uses ED CB A registers for FP - ld b, h - ld c, l - - ld a, e - or d - or c - or b - ret z ; Returns 0 if BC=DE=0 - - ; We already have a random 32 bit mantissa in ED CB - ; From 0001h to FFFFh - - ld l, 81h ; Exponent - ; At this point we have [0 .. 1) FP number; - - ; Now we must shift mantissa left until highest bit goes into carry - ld a, e ; Use A register for rotating E faster (using RLA instead of RL E) -RND_LOOP: - dec l - sla b - rl c - rl d - rla - jp nc, RND_LOOP - - ; Now undo last mantissa left-shift once - ccf ; Clears carry to insert a 0 bit back into mantissa -> positive FP number - rra - rr d - rr c - rr b - - ld e, a ; E must have the highest byte - ld a, l ; exponent in A - ret - - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/read_restore.asm b/src/lib/arch/zxnext/runtime/read_restore.asm index f97bc97f0..82afa7d77 100644 --- a/src/lib/arch/zxnext/runtime/read_restore.asm +++ b/src/lib/arch/zxnext/runtime/read_restore.asm @@ -1,362 +1,8 @@ -;; This implements READ & RESTORE functions -;; Reads a new element from the DATA Address code -;; Updates the DATA_ADDR read ptr for the next read - -;; Data codification is 1 byte for type followed by data bytes -;; Byte type is encoded as follows - -;; 00: End of data -;; 01: String -;; 02: Byte -;; 03: Ubyte -;; 04: Integer -;; 05: UInteger -;; 06: Long -;; 07: ULong -;; 08: Fixed -;; 09: Float - -;; bit7 is set for a parameter-less function -;; In that case, the next two bytes are the ptr of the function to jump - -#include once -#include once -#include once -#include once -#include once -#include once -#include once - -#define _str 1 -#define _i8 2 -#define _u8 3 -#define _i16 4 -#define _u16 5 -#define _i32 6 -#define _u32 7 -#define _f16 8 -#define _flt 9 - - -;; Updates restore point to the given HL mem. address - push namespace core - -__RESTORE: - PROC - LOCAL __DATA_ADDR - - ld (__DATA_ADDR), hl - ret - -;; Reads a value from the DATA mem area and updates __DATA_ADDR ptr to the -;; next item. On Out Of Data, restarts -;; -__READ: - LOCAL read_restart, cont, cont2, table, no_func - LOCAL dynamic_cast, dynamic_cast2, dynamic_cast3, dynamic_cast4 - LOCAL _decode_table, coerce_to_int, coerce_to_int2, promote_to_i16 - LOCAL _from_i8, _from_u8 - LOCAL _from_i16, _from_u16 - LOCAL _from_i32, _from_u32 - LOCAL _from_fixed, __data_error - - push af ; type of data to read - ld hl, (__DATA_ADDR) -read_restart: - ld a, (hl) - or a ; 0 => OUT of data - jr nz, cont - ;; Signals out of data - - ld hl, .DATA.__DATA__0 - ld (__DATA_ADDR), hl - jr read_restart ; Start again -cont: - and 0x80 - ld a, (hl) - push af - jp z, no_func ;; Loads data directly, not a function - inc hl - ld e, (hl) - inc hl - ld d, (hl) - inc hl - ld (__DATA_ADDR), hl ;; Store address of next DATA - ex de, hl -cont2: - ld de, dynamic_cast - push de ; ret address - jp (hl) ; "call (hl)" - - ;; Now tries to convert the given result to the expected type or raise an error -dynamic_cast: - exx - ex af, af' - pop af ; type READ - and 0x7F ; clear bit 7 - pop hl ; type requested by USER (type of the READ variable) - ld c, h ; save requested type (save it in register C) - cp h - exx - jr nz, dynamic_cast2 ; Types are identical? - ;; yes, they are - ex af, af' - ret - -dynamic_cast2: - cp _str ; Requested a number, but read a string? - jr nz, dynamic_cast3 - call __MEM_FREE ; Frees str from memory - jr __data_error - -dynamic_cast3: - exx - ld b, a ; Read type - ld a, c ; Requested type - cp _str - jr z, __data_error - cp b - jr c, dynamic_cast4 - ;; here the user expected type is "larger" than the read one - ld a, b - sub _i8 - add a, a - ld l, a - ld h, 0 - ld de, _decode_table - add hl, de - ld e, (hl) - inc hl - ld h, (hl) - ld l, e - push hl - ld a, c ; Requested type - exx - ret - -__data_error: - ;; When a data is read, but cannot be converted to the requested type - ;; that is, the user asked for a string and we read a number or vice versa - ld a, ERROR_InvalidArg - call __STOP ; The user expected a string, but read a number - xor a - ld h, a - ld l, a - ld e, a - ld d, a - ld b, a - ld c, a - ret - -_decode_table: - dw _from_i8 - dw _from_u8 - dw _from_i16 - dw _from_u16 - dw _from_i32 - dw _from_u32 - dw _from_fixed - -_from_i8: - cp _i16 - jr nc, promote_to_i16 - ex af, af' - ret ;; Was from Byte to Ubyte - -promote_to_i16: - ex af, af' - ld l, a - rla - sbc a, a - ld h, a ; copy sgn to h - ex af, af' - jr _before_from_i16 - -_from_u8: - ex af, af' - ld l, a - ld h, 0 - ex af, af' - ;; Promoted to i16 - -_before_from_i16: -_from_i16: - cp _i32 - ret c ;; from i16 to u16 - ;; Promote i16 to i32 - ex af, af' - ld a, h - rla - sbc a, a - ld e, a - ld d, a - ex af, af' -_from_i32: - cp _u32 - ret z ;; From i32 to u32 - ret c ;; From u16 to i32 - cp _flt - jp z, __I32TOFREG -_from_u32: - cp _flt - jp z, __U32TOFREG - ex de, hl - ld hl, 0 - cp _f16 - ret z -_from_fixed: ;; From fixed to float - jp __F16TOFREG -_from_u16: - ld de, 0 ; HL 0x0000 => 32 bits - jp _from_i32 - -dynamic_cast4: - ;; The user type is "shorter" than the read one - ld a, b ;; read type - cp _i16 ;; if user type < read type < _i16 => From Ubyte to Byte. Return af' - jr nc, 1f - ex af, af' - ret -1: - ld a, c ;; recover user required type - cp _f16 ;; required type - jr c, before_to_int ;; required < fixed (f16) - ex af, af' - exx ;; Ok, we must convert from float to f16 - jp __FTOF16REG - -before_to_int: - ld a, b ;; read type - cp _f16 ;; - jr c, coerce_to_int2 - jr nz, coerce_to_int ;; From float to int - ld a, c ;; user type - exx - ;; f16 to Long - ex de, hl - ld a, h - rla - sbc a, a - ld d, a - ld e, a - exx - jr coerce_to_int2 -coerce_to_int: - exx - ex af, af' - call __FTOU32REG - ex af, af' ; a contains user type - exx -coerce_to_int2: ; At this point we have an u/integer in hl - exx - cp _i16 - ret nc ; Already done. Return the result - ld a, l ; Truncate to byte - ret - -no_func: - exx - ld de, dynamic_cast - push de ; Ret address - dec a ; 0 => string; 1, 2 => byte; 3, 4 => integer; 5, 6 => long, 7 => fixed; 8 => float - ld h, 0 - add a, a - ld l, a - ld de, table - add hl, de - ld e, (hl) - inc hl - ld h, (hl) - ld l, e - push hl ; address to jump to - exx - inc hl - ret ; jp (sp) => jump to table[a - 1] - -table: - LOCAL __01_decode_string - LOCAL __02_decode_byte - LOCAL __03_decode_ubyte - LOCAL __04_decode_integer - LOCAL __05_decode_uinteger - LOCAL __06_decode_long - LOCAL __07_decode_ulong - LOCAL __08_decode_fixed - LOCAL __09_decode_float - - ;; 1 -> Decode string - ;; 2, 3 -> Decode Byte, UByte - ;; 4, 5 -> Decode Integer, UInteger - ;; 6, 7 -> Decode Long, ULong - ;; 8 -> Decode Fixed - ;; 9 -> Decode Float - dw __01_decode_string - dw __02_decode_byte - dw __03_decode_ubyte - dw __04_decode_integer - dw __05_decode_uinteger - dw __06_decode_long - dw __07_decode_ulong - dw __08_decode_fixed - dw __09_decode_float - -__01_decode_string: - ld e, (hl) - inc hl - ld d, (hl) - inc hl - ld (__DATA_ADDR), hl ;; Store address of next DATA - ex de, hl - jp __LOADSTR - -__02_decode_byte: -__03_decode_ubyte: - ld a, (hl) - inc hl - ld (__DATA_ADDR), hl - ret - -__04_decode_integer: -__05_decode_uinteger: - ld e, (hl) - inc hl - ld d, (hl) - inc hl - ld (__DATA_ADDR), hl - ex de, hl - ret - -__06_decode_long: -__07_decode_ulong: -__08_decode_fixed: - ld b, h - ld c, l - inc bc - inc bc - inc bc - inc bc - ld (__DATA_ADDR), bc - jp __ILOAD32 - -__09_decode_float: - call __LOADF - inc hl - ld (__DATA_ADDR), hl - ld h, a ; returns A in H; sets A free - ret - -__DATA_ADDR: ;; Stores current DATA ptr - dw .DATA.__DATA__0 - ENDP - -#undef _str -#undef _i8 -#undef _u8 -#undef _i16 -#undef _u16 -#undef _i32 -#undef _u32 -#undef _f16 -#undef _flt - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/save.asm b/src/lib/arch/zxnext/runtime/save.asm index 791088bab..a78a5f67a 100644 --- a/src/lib/arch/zxnext/runtime/save.asm +++ b/src/lib/arch/zxnext/runtime/save.asm @@ -1,186 +1,8 @@ -; Save code "XXX" at address YYY of length ZZZ -; Parameters in the stack are XXX (16 bit) address of string name -; (only first 12 chars will be taken into account) -; YYY and ZZZ are 16 bit on top of the stack. - -#include once -#include once - - push namespace core - -SAVE_CODE: - - PROC - - LOCAL MEMBOT - LOCAL SAVE_CONT - LOCAL ROM_SAVE - LOCAL __ERR_EMPTY - LOCAL SAVE_STOP - LOCAL STR_PTR - LOCAL SAVE_EMPTY_ERROR - -#ifdef __ENABLE_BREAK__ - ROM_SAVE EQU 0970h -#endif - MEMBOT EQU 23698 ; Use the CALC mem to store header - STR_PTR EQU MEMBOT + 17 - - pop hl ; Return address - pop bc ; data length in bytes - pop de ; address start - ex (sp), hl ; CALLE => now hl = String - ld (STR_PTR), hl - -; This function will call the ROM SAVE CODE Routine -; Parameters in the stack are HL => String with SAVE name -; (only first 12 chars will be taken into account) -; DE = START address of CODE to save -; BC = Length of data in bytes - -__SAVE_CODE: ; INLINE version - ld a, b - or c - jr z, SAVE_EMPTY_ERROR ; Return if block length == 0 - - push ix - ld a, h - or l - jr z, __ERR_EMPTY ; Return if NULL STRING - - ld ix, MEMBOT - ld (ix + 00), 3 ; CODE - - ld (ix + 11), c - ld (ix + 12), b ; Store long in bytes - ld (ix + 13), e - ld (ix + 14), d ; Store address in bytes - - push hl - ld bc, 9 - ld HL, MEMBOT + 1 - ld DE, MEMBOT + 2 - ld (hl), ' ' - ldir ; Fill the filename with blanks - pop hl - - ld c, (hl) - inc hl - ld b, (hl) - inc hl - ld a, b - or c - -__ERR_EMPTY: - ld a, ERROR_InvalidFileName - jr z, SAVE_STOP ; Return if str len == 0 - - ex de, hl ; Saves HL in DE - ld hl, 10 - or a - sbc hl, bc ; Test BC > 10? - ex de, hl - jr nc, SAVE_CONT ; Ok BC <= 10 - ld bc, 10 ; BC at most 10 chars - -SAVE_CONT: - ld de, MEMBOT + 1 - ldir ; Copy String block NAME - ld hl, (STR_PTR) - call MEM_FREE - ld l, (ix + 13) - ld h, (ix + 14) ; Restores start of bytes - - ld a, r - push af - call ROM_SAVE - - LOCAL NO_INT - pop af - jp po, NO_INT - ei -NO_INT: - ; Recovers ECHO_E since ROM SAVE changes it - ld hl, 1821h - ld (23682), hl - pop ix - ret - -SAVE_EMPTY_ERROR: - ld a, ERROR_InvalidArg - -SAVE_STOP: - pop ix - push af - ld hl, (STR_PTR) - call MEM_FREE - pop af - jp __STOP - -#ifndef __ENABLE_BREAK__ - LOCAL CHAN_OPEN - LOCAL PO_MSG - LOCAL WAIT_KEY - LOCAL SA_BYTES - LOCAL SA_CHK_BRK - LOCAL SA_CONT - - CHAN_OPEN EQU 1601h - PO_MSG EQU 0C0Ah - WAIT_KEY EQU 15D4h - SA_BYTES EQU 04C6h - -ROM_SAVE: - push hl - ld a, 0FDh - call CHAN_OPEN - xor a - ld de, 09A1h - call PO_MSG - set 5, (iy + 02h) - call WAIT_KEY - push ix - ld de, 0011h - xor a - call SA_BYTES - pop ix - - call SA_CHK_BRK - jr c, SA_CONT - pop ix - ret - -SA_CONT: - ei - ld b, 32h - -LOCAL SA_1_SEC -SA_1_SEC: - halt - djnz SA_1_SEC - - ld e, (ix + 0Bh) - ld d, (ix + 0Ch) - ld a, 0FFh - pop ix - call SA_BYTES - -SA_CHK_BRK: - ld b, a - ld a, (5C48h) - and 38h - rrca - rrca - rrca - out (0FEh), a - ld a, 7Fh - in a, (0FEh) - rra - ld a, b - ret - -#endif - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/set_pixel_addr_attr.asm b/src/lib/arch/zxnext/runtime/set_pixel_addr_attr.asm index 383d027da..1d03b7a2c 100644 --- a/src/lib/arch/zxnext/runtime/set_pixel_addr_attr.asm +++ b/src/lib/arch/zxnext/runtime/set_pixel_addr_attr.asm @@ -1,23 +1,8 @@ -#include once - -push namespace core - -; Sets the attribute at a given screen pixel address in hl -; HL contains the address in RAM for a given pixel (not a coordinate) -SET_PIXEL_ADDR_ATTR: - ;; gets ATTR position with offset given in SCREEN_ADDR - ld de, (SCREEN_ADDR) - or a - sbc hl, de - ld a, h - rrca - rrca - rrca - and 3 - ld h, a - - ld de, (SCREEN_ATTR_ADDR) - add hl, de ;; Final screen addr - jp __SET_ATTR2 - -pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/sposn.asm b/src/lib/arch/zxnext/runtime/sposn.asm index 223d8dd89..12b204802 100644 --- a/src/lib/arch/zxnext/runtime/sposn.asm +++ b/src/lib/arch/zxnext/runtime/sposn.asm @@ -1,58 +1,8 @@ -#include once -#include once - -; Printing positioning library. - push namespace core - -; Loads into DE current ROW, COL print position from S_POSN mem var. -__LOAD_S_POSN: - PROC - - ld de, (S_POSN) - ld hl, SCR_SIZE - or a - sbc hl, de - ex de, hl - ret - - ENDP - - -; Saves ROW, COL from DE into S_POSN mem var. -__SAVE_S_POSN: - PROC - - ld hl, SCR_SIZE - or a - sbc hl, de - ld (S_POSN), hl ; saves it again - -__SET_SCR_PTR: ;; Fast - push de - call __ATTR_ADDR - ld (DFCCL), hl - pop de - - ld a, d - ld c, a ; Saves it for later - - and 0F8h ; Masks 3 lower bit ; zy - ld d, a - - ld a, c ; Recovers it - and 07h ; MOD 7 ; y1 - rrca - rrca - rrca - - or e - ld e, a - - ld hl, (SCREEN_ADDR) - add hl, de ; HL = Screen address + DE - ld (DFCC), hl - ret - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/stackf.asm b/src/lib/arch/zxnext/runtime/stackf.asm index 5546bdd5a..a9aa18a47 100644 --- a/src/lib/arch/zxnext/runtime/stackf.asm +++ b/src/lib/arch/zxnext/runtime/stackf.asm @@ -1,49 +1,8 @@ -; ------------------------------------------------------------- -; Functions to manage FP-Stack of the ZX Spectrum ROM CALC -; ------------------------------------------------------------- - - - push namespace core - -__FPSTACK_PUSH EQU 2AB6h ; Stores an FP number into the ROM FP stack (A, ED CB) -__FPSTACK_POP EQU 2BF1h ; Pops an FP number out of the ROM FP stack (A, ED CB) - -__FPSTACK_PUSH2: ; Pushes Current A ED CB registers and top of the stack on (SP + 4) - ; Second argument to push into the stack calculator is popped out of the stack - ; Since the caller routine also receives the parameters into the top of the stack - ; four bytes must be removed from SP before pop them out - - call __FPSTACK_PUSH ; Pushes A ED CB into the FP-STACK - exx - pop hl ; Caller-Caller return addr - exx - pop hl ; Caller return addr - - pop af - pop de - pop bc - - push hl ; Caller return addr - exx - push hl ; Caller-Caller return addr - exx - - jp __FPSTACK_PUSH - - -__FPSTACK_I16: ; Pushes 16 bits integer in HL into the FP ROM STACK - ; This format is specified in the ZX 48K Manual - ; You can push a 16 bit signed integer as - ; 0 SS LL HH 0, being SS the sign and LL HH the low - ; and High byte respectively - ld a, h - rla ; sign to Carry - sbc a, a ; 0 if positive, FF if negative - ld e, a - ld d, l - ld c, h - xor a - ld b, a - jp __FPSTACK_PUSH - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/store32.asm b/src/lib/arch/zxnext/runtime/store32.asm index 753b20e28..a21256507 100644 --- a/src/lib/arch/zxnext/runtime/store32.asm +++ b/src/lib/arch/zxnext/runtime/store32.asm @@ -1,27 +1,8 @@ - push namespace core - -__PISTORE32: - push hl - push ix - pop hl - add hl, bc - pop bc - -__ISTORE32: ; Load address at hl, and stores E,D,B,C integer at that address - ld a, (hl) - inc hl - ld h, (hl) - ld l, a - -__STORE32: ; Stores the given integer in DEBC at address HL - ld (hl), c - inc hl - ld (hl), b - inc hl - ld (hl), e - inc hl - ld (hl), d - ret - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/storef.asm b/src/lib/arch/zxnext/runtime/storef.asm index bda382fcf..6cd101e51 100644 --- a/src/lib/arch/zxnext/runtime/storef.asm +++ b/src/lib/arch/zxnext/runtime/storef.asm @@ -1,32 +1,8 @@ - push namespace core - -__PISTOREF: ; Indect Stores a float (A, E, D, C, B) at location stored in memory, pointed by (IX + HL) - push de - ex de, hl ; DE <- HL - push ix - pop hl ; HL <- IX - add hl, de ; HL <- IX + HL - pop de - -__ISTOREF: ; Load address at hl, and stores A,E,D,C,B registers at that address. Modifies A' register - ex af, af' - ld a, (hl) - inc hl - ld h, (hl) - ld l, a ; HL = (HL) - ex af, af' - -__STOREF: ; Stores the given FP number in A EDCB at address HL - ld (hl), a - inc hl - ld (hl), e - inc hl - ld (hl), d - inc hl - ld (hl), c - inc hl - ld (hl), b - ret - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/storestr.asm b/src/lib/arch/zxnext/runtime/storestr.asm index 61dc63bdb..f907d1e4d 100644 --- a/src/lib/arch/zxnext/runtime/storestr.asm +++ b/src/lib/arch/zxnext/runtime/storestr.asm @@ -1,48 +1,8 @@ -; vim:ts=4:et:sw=4 -; Stores value of current string pointed by DE register into address pointed by HL -; Returns DE = Address pointer (&a$) -; Returns HL = HL (b$ => might be needed later to free it from the heap) +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; e.g. => HL = _variableName (DIM _variableName$) -; DE = Address into the HEAP -; -; This function will resize (REALLOC) the space pointed by HL -; before copying the content of b$ into a$ - - -#include once - - push namespace core - -__PISTORE_STR: ; Indirect assignment at (IX + BC) - push ix - pop hl - add hl, bc - -__ISTORE_STR: ; Indirect assignment, hl point to a pointer to a pointer to the heap! - ld c, (hl) - inc hl - ld h, (hl) - ld l, c ; HL = (HL) - -__STORE_STR: - push de ; Pointer to b$ - push hl ; Pointer to a$ - - ld c, (hl) - inc hl - ld h, (hl) - ld l, c ; HL = (HL) - - call __STRASSIGN ; HL (a$) = DE (b$); HL changed to a new dynamic memory allocation - ex de, hl ; DE = new address of a$ - pop hl ; Recover variable memory address pointer - - ld (hl), e - inc hl - ld (hl), d ; Stores a$ ptr into element ptr - - pop hl ; Returns ptr to b$ in HL (Caller might needed to free it from memory) - ret +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/storestr2.asm b/src/lib/arch/zxnext/runtime/storestr2.asm index 343d2c4a6..685fd9cec 100644 --- a/src/lib/arch/zxnext/runtime/storestr2.asm +++ b/src/lib/arch/zxnext/runtime/storestr2.asm @@ -1,42 +1,8 @@ -; Similar to __STORE_STR, but this one is called when -; the value of B$ if already duplicated onto the stack. -; So we needn't call STRASSING to create a duplication -; HL = address of string memory variable -; DE = address of 2n string. It just copies DE into (HL) -; freeing (HL) previously. - -#include once - - push namespace core - -__PISTORE_STR2: ; Indirect store temporary string at (IX + BC) - push ix - pop hl - add hl, bc - -__ISTORE_STR2: - ld c, (hl) ; Dereferences HL - inc hl - ld h, (hl) - ld l, c ; HL = *HL (real string variable address) - -__STORE_STR2: - push hl - ld c, (hl) - inc hl - ld h, (hl) - ld l, c ; HL = *HL (real string address) - - push de - call __MEM_FREE - pop de - - pop hl - ld (hl), e - inc hl - ld (hl), d - dec hl ; HL points to mem address variable. This might be useful in the future. - - ret - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/str.asm b/src/lib/arch/zxnext/runtime/str.asm index a3cc9b8d1..c3a18fb83 100644 --- a/src/lib/arch/zxnext/runtime/str.asm +++ b/src/lib/arch/zxnext/runtime/str.asm @@ -1,80 +1,8 @@ -; The STR$( ) BASIC function implementation - -; Given a FP number in C ED LH -; Returns a pointer (in HL) to the memory heap -; containing the FP number string representation - -#include once -#include once -#include once - - push namespace core - -__STR: - -__STR_FAST: - - PROC - LOCAL __STR_END - LOCAL RECLAIM2 - LOCAL STK_END - - ld hl, (STK_END) - push hl; Stores STK_END - ld hl, (ATTR_T) ; Saves ATTR_T since it's changed by STR$ due to a ROM BUG - push hl - - call __FPSTACK_PUSH ; Push number into stack - rst 28h ; # Rom Calculator - defb 2Eh ; # STR$(x) - defb 38h ; # END CALC - call __FPSTACK_POP ; Recovers string parameters to A ED CB (Only ED LH are important) - - pop hl - ld (ATTR_T), hl ; Restores ATTR_T - pop hl - ld (STK_END), hl ; Balance STK_END to avoid STR$ bug - - push bc - push de - - inc bc - inc bc - call __MEM_ALLOC ; HL Points to new block - - pop de - pop bc - - push hl - ld a, h - or l - jr z, __STR_END ; Return if NO MEMORY (NULL) - - push bc - push de - ld (hl), c - inc hl - ld (hl), b - inc hl ; Copies length - - ex de, hl ; HL = start of original string - ldir ; Copies string content - - pop de ; Original (ROM-CALC) string - pop bc ; Original Length - -__STR_END: - ex de, hl - inc bc - - call RECLAIM2 ; Frees TMP Memory - pop hl ; String result - - ret - -RECLAIM2 EQU 19E8h -STK_END EQU 5C65h - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/strcat.asm b/src/lib/arch/zxnext/runtime/strcat.asm index 1d1ed1829..cac2544e5 100644 --- a/src/lib/arch/zxnext/runtime/strcat.asm +++ b/src/lib/arch/zxnext/runtime/strcat.asm @@ -1,129 +1,8 @@ -#include once -#include once - - push namespace core - -__ADDSTR: ; Implements c$ = a$ + b$ - ; hl = &a$, de = &b$ (pointers) - - -__STRCAT2: ; This routine creates a new string in dynamic space - ; making room for it. Then copies a$ + b$ into it. - ; HL = a$, DE = b$ - - PROC - - LOCAL __STR_CONT - LOCAL __STRCATEND - - push hl - call __STRLEN - ld c, l - ld b, h ; BC = LEN(a$) - ex (sp), hl ; (SP) = LEN (a$), HL = a$ - push hl ; Saves pointer to a$ - - inc bc - inc bc ; +2 bytes to store length - - ex de, hl - push hl - call __STRLEN - ; HL = len(b$) - - add hl, bc ; Total str length => 2 + len(a$) + len(b$) - - ld c, l - ld b, h ; BC = Total str length + 2 - call __MEM_ALLOC - pop de ; HL = c$, DE = b$ - - ex de, hl ; HL = b$, DE = c$ - ex (sp), hl ; HL = a$, (SP) = b$ - - exx - pop de ; D'E' = b$ - exx - - pop bc ; LEN(a$) - - ld a, d - or e - ret z ; If no memory: RETURN - -__STR_CONT: - push de ; Address of c$ - - ld a, h - or l - jr nz, __STR_CONT1 ; If len(a$) != 0 do copy - - ; a$ is NULL => uses HL = DE for transfer - ld h, d - ld l, e - ld (hl), a ; This will copy 00 00 at (DE) location - inc de ; - dec bc ; Ensure BC will be set to 1 in the next step - -__STR_CONT1: ; Copies a$ (HL) into c$ (DE) - inc bc - inc bc ; BC = BC + 2 - ldir ; MEMCOPY: c$ = a$ - pop hl ; HL = c$ - - exx - push de ; Recovers b$; A ex hl,hl' would be very handy - exx - - pop de ; DE = b$ - -__STRCAT: ; ConCATenate two strings a$ = a$ + b$. HL = ptr to a$, DE = ptr to b$ - ; NOTE: Both DE, BC and AF are modified and lost - ; Returns HL (pointer to a$) - ; a$ Must be NOT NULL - ld a, d - or e - ret z ; Returns if de is NULL (nothing to copy) - - push hl ; Saves HL to return it later - - ld c, (hl) - inc hl - ld b, (hl) - inc hl - add hl, bc ; HL = end of (a$) string ; bc = len(a$) - push bc ; Saves LEN(a$) for later - - ex de, hl ; DE = end of string (Begin of copy addr) - ld c, (hl) - inc hl - ld b, (hl) ; BC = len(b$) - - ld a, b - or c - jr z, __STRCATEND; Return if len(b$) == 0 - - push bc ; Save LEN(b$) - inc hl ; Skip 2nd byte of len(b$) - ldir ; Concatenate b$ - - pop bc ; Recovers length (b$) - pop hl ; Recovers length (a$) - add hl, bc ; HL = LEN(a$) + LEN(b$) = LEN(a$+b$) - ex de, hl ; DE = LEN(a$+b$) - pop hl - - ld (hl), e ; Updates new LEN and return - inc hl - ld (hl), d - dec hl - ret - -__STRCATEND: - pop hl ; Removes Len(a$) - pop hl ; Restores original HL, so HL = a$ - ret - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/strcpy.asm b/src/lib/arch/zxnext/runtime/strcpy.asm index d864623d2..5b2e6463b 100644 --- a/src/lib/arch/zxnext/runtime/strcpy.asm +++ b/src/lib/arch/zxnext/runtime/strcpy.asm @@ -1,99 +1,8 @@ -#include once - -; String library - - - push namespace core - -__STRASSIGN: ; Performs a$ = b$ (HL = address of a$; DE = Address of b$) - PROC - - LOCAL __STRREALLOC - LOCAL __STRCONTINUE - LOCAL __B_IS_NULL - LOCAL __NOTHING_TO_COPY - - ld b, d - ld c, e - ld a, b - or c - jr z, __B_IS_NULL - - ex de, hl - ld c, (hl) - inc hl - ld b, (hl) - dec hl ; BC = LEN(b$) - ex de, hl ; DE = &b$ - -__B_IS_NULL: ; Jumps here if B$ pointer is NULL - inc bc - inc bc ; BC = BC + 2 ; (LEN(b$) + 2 bytes for storing length) - - push de - push hl - - ld a, h - or l - jr z, __STRREALLOC - - dec hl - ld d, (hl) - dec hl - ld e, (hl) ; DE = MEMBLOCKSIZE(a$) - dec de - dec de ; DE = DE - 2 ; (Membloksize takes 2 bytes for memblock length) - - ld h, b - ld l, c ; HL = LEN(b$) + 2 => Minimum block size required - ex de, hl ; Now HL = BLOCKSIZE(a$), DE = LEN(b$) + 2 - - or a ; Prepare to subtract BLOCKSIZE(a$) - LEN(b$) - sbc hl, de ; Carry if len(b$) > Blocklen(a$) - jr c, __STRREALLOC ; No need to realloc - ; Need to reallocate at least to len(b$) + 2 - ex de, hl ; DE = Remaining bytes in a$ mem block. - ld hl, 4 - sbc hl, de ; if remaining bytes < 4 we can continue - jr nc,__STRCONTINUE ; Otherwise, we realloc, to free some bytes - -__STRREALLOC: - pop hl - call __REALLOC ; Returns in HL a new pointer with BC bytes allocated - push hl - -__STRCONTINUE: ; Pops hl and de SWAPPED - pop de ; DE = &a$ - pop hl ; HL = &b$ - - ld a, d ; Return if not enough memory for new length - or e - ret z ; Return if DE == NULL (0) - -__STRCPY: ; Copies string pointed by HL into string pointed by DE - ; Returns DE as HL (new pointer) - ld a, h - or l - jr z, __NOTHING_TO_COPY - ld c, (hl) - inc hl - ld b, (hl) - dec hl - inc bc - inc bc - push de - ldir - pop hl - ret - -__NOTHING_TO_COPY: - ex de, hl - ld (hl), e - inc hl - ld (hl), d - dec hl - ret - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/strictbool.asm b/src/lib/arch/zxnext/runtime/strictbool.asm index 80a7460a4..ab3cb5888 100644 --- a/src/lib/arch/zxnext/runtime/strictbool.asm +++ b/src/lib/arch/zxnext/runtime/strictbool.asm @@ -1,12 +1,8 @@ -; This routine is called if --strict-boolean was set at the command line. -; It will make any boolean result to be always 0 or 1 +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - push namespace core - -__NORMALIZE_BOOLEAN: - sub 1 - sbc a, a - inc a - ret - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/strlen.asm b/src/lib/arch/zxnext/runtime/strlen.asm index cb4a880af..f02bd8700 100644 --- a/src/lib/arch/zxnext/runtime/strlen.asm +++ b/src/lib/arch/zxnext/runtime/strlen.asm @@ -1,20 +1,8 @@ -; Returns len if a string -; If a string is NULL, its len is also 0 -; Result returned in HL - - push namespace core - -__STRLEN: ; Direct FASTCALL entry - ld a, h - or l - ret z - - ld a, (hl) - inc hl - ld h, (hl) ; LEN(str) in HL - ld l, a - ret - - pop namespace - - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/strslice.asm b/src/lib/arch/zxnext/runtime/strslice.asm index c63ad4e47..8d9a4d425 100644 --- a/src/lib/arch/zxnext/runtime/strslice.asm +++ b/src/lib/arch/zxnext/runtime/strslice.asm @@ -1,109 +1,8 @@ -; String slicing library -; HL = Str pointer -; DE = String start -; BC = String character end -; A register => 0 => the HL pointer wont' be freed from the HEAP -; e.g. a$(5 TO 10) => HL = a$; DE = 5; BC = 10 - -; This implements a$(X to Y) being X and Y first and -; last characters respectively. If X > Y, NULL is returned - -; Otherwise returns a pointer to a$ FROM X to Y (starting from 0) -; if Y > len(a$), then a$ will be padded with spaces (reallocating -; it in dynamic memory if needed). Returns pointer (HL) to resulting -; string. NULL (0) if no memory for padding. +; ---------------------------------------------------------------- +; This file is released under the MIT License ; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- -#include once -#include once -#include once - - push namespace core - -__STRSLICE: ; Callee entry - pop hl ; Return ADDRESS - pop bc ; Last char pos - pop de ; 1st char pos - ex (sp), hl ; CALLEE. -> String start - -__STRSLICE_FAST: ; __FASTCALL__ Entry - PROC - - LOCAL __CONT - LOCAL __EMPTY - LOCAL __FREE_ON_EXIT - - push hl ; Stores original HL pointer to be recovered on exit - ex af, af' ; Saves A register for later - - push hl - call __STRLEN - inc bc ; Last character position + 1 (string starts from 0) - or a - sbc hl, bc ; Compares length with last char position - jr nc, __CONT ; If Carry => We must copy to end of string - add hl, bc ; Restore back original LEN(a$) in HL - ld b, h - ld c, l ; Copy to the end of str - ccf ; Clears Carry flag for next subtraction - -__CONT: - ld h, b - ld l, c ; HL = Last char position to copy (1 for char 0, 2 for char 1, etc) - sbc hl, de ; HL = LEN(a$) - DE => Number of chars to copy - jr z, __EMPTY ; 0 Chars to copy => Return HL = 0 (NULL STR) - jr c, __EMPTY ; If Carry => Nothing to return (NULL STR) - - ld b, h - ld c, l ; BC = Number of chars to copy - inc bc - inc bc ; +2 bytes for string length number - - push bc - push de - call __MEM_ALLOC - pop de - pop bc - ld a, h - or l - jr z, __EMPTY ; Return if NULL (no memory) - - dec bc - dec bc ; Number of chars to copy (Len of slice) - - ld (hl), c - inc hl - ld (hl), b - inc hl ; Stores new string length - - ex (sp), hl ; Pointer to A$ now in HL; Pointer to new string chars in Stack - inc hl - inc hl ; Skip string length - add hl, de ; Were to start from A$ - pop de ; Start of new string chars - push de ; Stores it again - ldir ; Copies BC chars - pop de - dec de - dec de ; Points to String LEN start - ex de, hl ; Returns it in HL - jr __FREE_ON_EXIT - -__EMPTY: ; Return NULL (empty) string - pop hl - ld hl, 0 ; Return NULL - - -__FREE_ON_EXIT: - ex af, af' ; Recover original A register - ex (sp), hl ; Original HL pointer - - or a - call nz, __MEM_FREE - - pop hl ; Recover result - ret - - ENDP - - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/swap32.asm b/src/lib/arch/zxnext/runtime/swap32.asm index d615c7127..3158f67a3 100644 --- a/src/lib/arch/zxnext/runtime/swap32.asm +++ b/src/lib/arch/zxnext/runtime/swap32.asm @@ -1,20 +1,8 @@ -; Exchanges current DE HL with the -; ones in the stack - - push namespace core - -__SWAP32: - pop bc ; Return address - ex (sp), hl - inc sp - inc sp - ex de, hl - ex (sp), hl - ex de, hl - dec sp - dec sp - push bc - ret - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/table_jump.asm b/src/lib/arch/zxnext/runtime/table_jump.asm index 370d2faf8..b58b92254 100644 --- a/src/lib/arch/zxnext/runtime/table_jump.asm +++ b/src/lib/arch/zxnext/runtime/table_jump.asm @@ -1,21 +1,8 @@ - - push namespace core - -JUMP_HL_PLUS_2A: ; Does JP (HL + A*2) Modifies DE. Modifies A - add a, a - -JUMP_HL_PLUS_A: ; Does JP (HL + A) Modifies DE - ld e, a - ld d, 0 - -JUMP_HL_PLUS_DE: ; Does JP (HL + DE) - add hl, de - ld e, (hl) - inc hl - ld d, (hl) - ex de, hl -CALL_HL: - jp (hl) - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/u32tofreg.asm b/src/lib/arch/zxnext/runtime/u32tofreg.asm index 19adf7cb7..ed808145c 100644 --- a/src/lib/arch/zxnext/runtime/u32tofreg.asm +++ b/src/lib/arch/zxnext/runtime/u32tofreg.asm @@ -1,93 +1,8 @@ -#include once - push namespace core - -__I8TOFREG: - ld l, a - rlca - sbc a, a ; A = SGN(A) - ld h, a - ld e, a - ld d, a - -__I32TOFREG: ; Converts a 32bit signed integer (stored in DEHL) - ; to a Floating Point Number returned in (A ED CB) - - ld a, d - or a ; Test sign - - jp p, __U32TOFREG ; It was positive, proceed as 32bit unsigned - - call __NEG32 ; Convert it to positive - call __U32TOFREG ; Convert it to Floating point - - set 7, e ; Put the sign bit (negative) in the 31bit of mantissa - ret - -__U8TOFREG: - ; Converts an unsigned 8 bit (A) to Floating point - ld l, a - ld h, 0 - ld e, h - ld d, h - -__U32TOFREG: ; Converts an unsigned 32 bit integer (DEHL) - ; to a Floating point number returned in A ED CB - - PROC - - LOCAL __U32TOFREG_END - - ld a, d - or e - or h - or l - ld b, d - ld c, e ; Returns 00 0000 0000 if ZERO - ret z - - push de - push hl - - exx - pop de ; Loads integer into B'C' D'E' - pop bc - exx - - ld l, 128 ; Exponent - ld bc, 0 ; DEBC = 0 - ld d, b - ld e, c - -__U32TOFREG_LOOP: ; Also an entry point for __F16TOFREG - exx - ld a, d ; B'C'D'E' == 0 ? - or e - or b - or c - jp z, __U32TOFREG_END ; We are done - - srl b ; Shift B'C' D'E' >> 1, output bit stays in Carry - rr c - rr d - rr e - exx - - rr e ; Shift EDCB >> 1, inserting the carry on the left - rr d - rr c - rr b - - inc l ; Increment exponent - jp __U32TOFREG_LOOP - - -__U32TOFREG_END: - exx - ld a, l ; Puts the exponent in a - res 7, e ; Sets the sign bit to 0 (positive) - - ret - ENDP - - pop namespace - +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/usr.asm b/src/lib/arch/zxnext/runtime/usr.asm index 12e89485d..c5e3b276d 100644 --- a/src/lib/arch/zxnext/runtime/usr.asm +++ b/src/lib/arch/zxnext/runtime/usr.asm @@ -1,21 +1,8 @@ -; Emulates the USR Sinclair BASIC function -; Result value returns in BC -; We use HL for returning values, su we must -; copy BC into HL before returning +; ---------------------------------------------------------------- +; This file is released under the MIT License ; -; The incoming parameter is HL (Address to JUMP) -; - -#include once - - push namespace core - -USR: - push ix ; must preserve IX - call CALL_HL - pop ix - ld h, b - ld l, c - ret +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- - pop namespace +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/usr_str.asm b/src/lib/arch/zxnext/runtime/usr_str.asm index 2753397fa..0401a8798 100644 --- a/src/lib/arch/zxnext/runtime/usr_str.asm +++ b/src/lib/arch/zxnext/runtime/usr_str.asm @@ -1,73 +1,8 @@ -; This function just returns the address of the UDG of the given str. -; If the str is EMPTY or not a letter, 0 is returned and ERR_NR set -; to "A: Invalid Argument" - -; On entry HL points to the string -; and A register is non-zero if the string must be freed (TMP string) - -#include once -#include once -#include once - - push namespace core - -USR_STR: - PROC - ex af, af' ; Saves A flag - - ld a, h - or l - jr z, USR_ERROR ; a$ = NULL => Invalid Arg - - ld d, h ; Saves HL in DE, for - ld e, l ; later usage - - ld c, (hl) - inc hl - ld a, (hl) - or c - jr z, USR_ERROR ; a$ = "" => Invalid Arg - - inc hl - ld a, (hl) ; Only the 1st char is needed - and %11011111 ; Convert it to UPPER CASE - sub 144 ; CODE(UDG "A") - jr nc, CONT - add a, 144 ; It was a letter - sub 'A' - - LOCAL CONT -CONT: - - ld l, a - ld h, 0 - add hl, hl - add hl, hl - add hl, hl ; hl = A * 8 - ld bc, (UDG) - add hl, bc - - ;; Now checks if the string must be released - ex af, af' ; Recovers A flag - or a - ret z ; return if not - - push hl ; saves result since __MEM_FREE changes HL - ex de, hl ; Recovers original HL value - call __MEM_FREE - pop hl - ret - -USR_ERROR: - ex de, hl ; Recovers original HL value - ex af, af' ; Recovers A flag - or a - call nz, __MEM_FREE - - ld a, ERROR_InvalidArg - ld (ERR_NR), a - ld hl, 0 - ret - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k] diff --git a/src/lib/arch/zxnext/runtime/val.asm b/src/lib/arch/zxnext/runtime/val.asm index 988b06907..6ec2ee9e5 100644 --- a/src/lib/arch/zxnext/runtime/val.asm +++ b/src/lib/arch/zxnext/runtime/val.asm @@ -1,120 +1,8 @@ -#include once -#include once -#include once - - push namespace core - -VAL: ; Computes VAL(a$) using ROM FP-CALC - ; HL = address of a$ - ; Returns FP number in C ED LH registers - ; A Register = 1 => Free a$ on return - - PROC - - LOCAL STK_STO_S - LOCAL __RET_ZERO - LOCAL ERR_SP - LOCAL STKBOT - LOCAL RECLAIM1 - LOCAL CH_ADD - LOCAL __VAL_ERROR - LOCAL __VAL_EMPTY - LOCAL SET_MIN - -RECLAIM1 EQU 6629 -STKBOT EQU 23651 -ERR_SP EQU 23613 -CH_ADD EQU 23645 -STK_STO_S EQU 2AB2h -SET_MIN EQU 16B0h - - ld d, a ; Preserves A register in DE - ld a, h - or l - jr z, __RET_ZERO ; NULL STRING => Return 0 - - push de ; Saves A Register (now in D) - push hl ; Not null string. Save its address for later - - ld c, (hl) - inc hl - ld b, (hl) - inc hl - - ld a, b - or c - jr z, __VAL_EMPTY ; Jumps VAL_EMPTY on empty string - - ex de, hl ; DE = String start - - ld hl, (CH_ADD) - push hl - - ld hl, (STKBOT) - push hl - - ld hl, (ERR_SP) - push hl - - ;; Now put our error handler on ERR_SP - ld hl, __VAL_ERROR - push hl - ld (ERR_SP), sp - - call STK_STO_S ; Enter it on the stack - - ld b, 1Dh ; "VAL" - rst 28h ; ROM CALC - defb 1Dh ; VAL - defb 38h ; END CALC - - pop hl ; Discards our current error handler - pop hl - ld (ERR_SP), hl ; Restores ERR_SP - - pop de ; old STKBOT - ld hl, (STKBOT) ; current SKTBOT - call RECLAIM1 ; Recover unused space - - pop hl ; Discards old CH_ADD value - pop hl ; String pointer - pop af ; Deletion flag - or a - call nz, __MEM_FREE ; Frees string content before returning - - ld a, ERROR_Ok ; Sets OK in the result - ld (ERR_NR), a - - jp __FPSTACK_POP ; Recovers result and return from there - -__VAL_ERROR: ; Jumps here on ERROR - pop hl - ld (ERR_SP), hl ; Restores ERR_SP - - ld hl, (STKBOT) ; current SKTBOT - pop de ; old STKBOT - pop hl - ld (CH_ADD), hl ; Recovers old CH_ADD - - call 16B0h ; Resets temporary areas after an error - -__VAL_EMPTY: ; Jumps here on empty string - pop hl ; Recovers initial string address - pop af ; String flag: If not 0 => it's temporary - or a - call nz, __MEM_FREE ; Frees "" string - -__RET_ZERO: ; Returns 0 Floating point on error - ld a, ERROR_InvalidArg - ld (ERR_NR), a - - xor a - ld b, a - ld c, a - ld d, b - ld e, c - ret - - ENDP - - pop namespace +; ---------------------------------------------------------------- +; This file is released under the MIT License +; +; Copyleft (k) 2008 +; by Jose Rodriguez-Rosa (a.k.a. Boriel) +; ---------------------------------------------------------------- + +#include once [arch:zx48k]