Skip to content

Commit b25dac7

Browse files
authored
Merge pull request #519 from boriel/feature/move_asm_lib_to_CORE_namespace
Feature/move asm lib to core namespace
2 parents 5cbc10f + 90e0678 commit b25dac7

946 files changed

Lines changed: 7828 additions & 6743 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/api/global_.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@
117117
# ----------------------------------------------------------------------
118118
SIZE_TYPE = None
119119

120+
# ----------------------------------------------------------------------
121+
# DATA Labels namespace
122+
# ----------------------------------------------------------------------
123+
DATAS_NAMESPACE = '.DATA'
124+
120125
# ----------------------------------------------------------------------
121126
# Data Type used for string chars index. Must be an integral
122127
# ----------------------------------------------------------------------

src/api/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def current_data_label() -> str:
110110
""" Returns a data label to which all labels must point to, until
111111
a new DATA line is declared
112112
"""
113-
return '__DATA__{0}'.format(len(global_.DATAS))
113+
return f'{global_.DATAS_NAMESPACE}.__DATA__{len(global_.DATAS)}'
114114

115115

116116
def flatten_list(x: Iterable[Any], iterables=(list, )) -> List[Any]:

src/arch/zx48k/backend/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,8 +2232,8 @@ def emit_start():
22322232

22332233
heap_init.append('; Defines USER DATA Length in bytes\n' +
22342234
f'{NAMESPACE}ZXBASIC_USER_DATA_LEN EQU {DATA_END_LABEL} - {DATA_LABEL}')
2235-
heap_init.append(f'{NAMESPACE}.__LABEL__.ZXBASIC_USER_DATA_LEN EQU {NAMESPACE}ZXBASIC_USER_DATA_LEN')
2236-
heap_init.append(f'{NAMESPACE}.__LABEL__.ZXBASIC_USER_DATA EQU {DATA_LABEL}')
2235+
heap_init.append(f'{NAMESPACE}__LABEL__.ZXBASIC_USER_DATA_LEN EQU {NAMESPACE}ZXBASIC_USER_DATA_LEN')
2236+
heap_init.append(f'{NAMESPACE}__LABEL__.ZXBASIC_USER_DATA EQU {DATA_LABEL}')
22372237

22382238
output.append('%s:' % START_LABEL)
22392239
if OPTIONS.headerless:

src/arch/zx48k/library-asm/read_restore.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ read_restart:
6868
jr nz, cont
6969
;; Signals out of data
7070

71-
ld hl, __DATA__0
71+
ld hl, .DATA.__DATA__0
7272
ld (__DATA_ADDR), hl
7373
jr read_restart ; Start again
7474
cont:
@@ -339,7 +339,7 @@ __09_decode_float:
339339
ret
340340

341341
__DATA_ADDR: ;; Stores current DATA ptr
342-
dw __DATA__0
342+
dw .DATA.__DATA__0
343343
ENDP
344344

345345
#undef _str

src/arch/zx48k/library/SP/Fill.bas

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ REM Avoid double inclusion
99

1010
SUB FASTCALL SPFill(xCoord as uByte, yCoord as uByte, fillPatternAddress as uInteger)
1111
asm
12+
push namespace core
13+
1214
PROC
1315
LOCAL SPPFill
1416
LOCAL SPPFill_start
@@ -27,12 +29,6 @@ ret
2729
; SPFill
2830
;
2931

30-
#include once <SP/PixelUp.asm>
31-
#include once <SP/PixelDown.asm>
32-
#include once <SP/CharLeft.asm>
33-
#include once <SP/CharRight.asm>
34-
#include once <SP/GetScrnAddr.asm>
35-
3632
; Patterned Flood Fill
3733
; Alvin Albrecht 2002
3834
; Tweaked to work in ZX Basic by Britlion, 2012.
@@ -540,8 +536,16 @@ endapply:
540536
SPPFill_end:
541537
LD IX,(SPPFill_IXBuffer)
542538
ENDP
539+
540+
pop namespace
543541
END ASM
544542
END SUB
545543

544+
#require "SP/PixelUp.asm"
545+
#require "SP/PixelDown.asm"
546+
#require "SP/CharLeft.asm"
547+
#require "SP/CharRight.asm"
548+
#require "SP/GetScrnAddr.asm"
549+
546550
#endif
547551

src/arch/zx48k/library/alloc.bas

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
' ----------------------------------------------------------------
22
' This file is released under the MIT License
3-
'
3+
'
44
' Copyleft (k) 2008
55
' by Jose Rodriguez-Rosa (a.k.a. Boriel) <http://www.boriel.com>
66
' ----------------------------------------------------------------
@@ -20,8 +20,8 @@ REM Avoid recursive / multiple inclusion
2020
' Allocates the requested bytes in the heap (dynamic memory) and
2121
' returns the address (16 bit, unsigned) of the new bloc. If
2222
' no memory, NULL (0) is returned.
23-
'
24-
' Parameters:
23+
'
24+
' Parameters:
2525
' n: number of bytes
2626
'
2727
' Returns:
@@ -34,9 +34,11 @@ function FASTCALL allocate(byval n as uinteger) as uinteger
3434
' 2.- Can return at any point with "ret"
3535
' 3.- The result (16bit) must be returned in HL
3636
asm
37-
ld b, h
38-
ld c, l
39-
jp __MEM_ALLOC ; Since malloc is FASTCALL, we can return from there
37+
push namespace core
38+
ld b, h
39+
ld c, l
40+
jp __MEM_ALLOC ; Since malloc is FASTCALL, we can return from there
41+
pop namespace
4042
end asm
4143
end function
4244

@@ -62,9 +64,11 @@ function FASTCALL callocate(byval n as uinteger) as uinteger
6264
' 2.- Can return at any point with "ret"
6365
' 3.- The result (16bit) must be returned in HL
6466
asm
65-
ld b, h
66-
ld c, l
67-
jp __MEM_CALLOC ; Since calloc is FASTCALL, we can return from there
67+
push namespace core
68+
ld b, h
69+
ld c, l
70+
jp __MEM_CALLOC ; Since calloc is FASTCALL, we can return from there
71+
pop namespace
6872
end asm
6973
end function
7074

@@ -80,7 +84,9 @@ sub FASTCALL deallocate(byval addr as integer)
8084
' 1.- The 16 bit 'n' parameter is received in hl
8185
' 2.- Can return at any point with "ret"
8286
asm
83-
jp __MEM_FREE
87+
push namespace core
88+
jp __MEM_FREE
89+
pop namespace
8490
end asm
8591
end sub
8692

@@ -91,8 +97,8 @@ end sub
9197
' Reallocates the requested bytes in the heap (dynamic memory) and
9298
' returns the address (16 bit, unsigned) of the new bloc. If
9399
' no memory, NULL (0) is returned.
94-
'
95-
' Parameters:
100+
'
101+
' Parameters:
96102
' n: number of bytes for the new size to reallocate
97103
'
98104
' Returns:
@@ -102,17 +108,19 @@ end sub
102108
function FASTCALL reallocate(byval addr as uinteger, byval n as uinteger) as uinteger
103109
' This is a FastCall function. This means:
104110
' 1.- The 16 bit 'n' parameter is received in hl
105-
' 2.- The 2nd parameter is in the stack (16 bit)
111+
' 2.- The 2nd parameter is in the stack (16 bit)
106112
' 3.- Can return at any point with "ret"
107113
' 4.- The result (16bit) must be returned in HL
108114
asm
109-
ex de, hl ; saves 'n' parameter in de
110-
pop hl ; return address
111-
ex (sp), hl ; hl -> now contains the 2nd parameter (new length)
112-
ld b, h
113-
ld c, l
114-
ex de, hl ; recovers hl (current pointer)
115-
jp __REALLOC ; Since realloc is FASTCALL, we can return from there
115+
push namespace core
116+
ex de, hl ; saves 'n' parameter in de
117+
pop hl ; return address
118+
ex (sp), hl ; hl -> now contains the 2nd parameter (new length)
119+
ld b, h
120+
ld c, l
121+
ex de, hl ; recovers hl (current pointer)
122+
jp __REALLOC ; Since realloc is FASTCALL, we can return from there
123+
pop namespace
116124
end asm
117125
end function
118126

@@ -125,6 +133,7 @@ end function
125133
' ----------------------------------------------------------------
126134
function FASTCALL memavail as uInteger
127135
asm
136+
push namespace core
128137
PROC
129138

130139
LOCAL LOOP
@@ -143,10 +152,10 @@ LOOP:
143152
ld a, (hl)
144153
inc hl
145154
ld h, (hl)
146-
ld l, a
155+
ld l, a
147156

148157
; DE += BC => Accum += Block size
149-
ex de, hl
158+
ex de, hl
150159
add hl, bc
151160
ex de, hl
152161

@@ -156,8 +165,9 @@ LOOP:
156165
jr nz, LOOP
157166

158167
ex de, hl
159-
160-
ENDP
168+
169+
ENDP
170+
pop namespace
161171
end asm
162172
end function
163173

@@ -169,6 +179,7 @@ end function
169179
' ----------------------------------------------------------------
170180
function FASTCALL maxavail as uInteger
171181
asm
182+
push namespace core
172183
PROC
173184

174185
LOCAL LOOP, CONT
@@ -187,19 +198,19 @@ LOOP:
187198
ld a, (hl)
188199
inc hl
189200
ld h, (hl)
190-
ld l, a
201+
ld l, a
191202

192203
; Test if DE >= BC
193204
; DE -= BC => Accum -= Block size
194-
ex de, hl
205+
ex de, hl
195206
or a
196207
sbc hl, bc ; set C if HL < BC
197208
add hl, bc ; Restores current value
198209
ex de, hl
199210

200211
; if not C skip this step
201212
jr nc, CONT
202-
; DE < BC => SET DE = BC
213+
; DE < BC => SET DE = BC
203214
ld d, b
204215
ld e, c
205216

@@ -210,8 +221,9 @@ CONT:
210221
jr nz, LOOP
211222

212223
ex de, hl
213-
214-
ENDP
224+
225+
ENDP
226+
pop namespace
215227
end asm
216228
end function
217229

@@ -223,5 +235,4 @@ end function
223235
#require "realloc.asm"
224236
#require "calloc.asm"
225237

226-
#endif
227-
238+
#endif

src/arch/zx48k/library/attr.bas

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
' ----------------------------------------------------------------
22
' This file is released under the MIT License
3-
'
3+
'
44
' Copyleft (k) 2008
55
' by Jose Rodriguez-Rosa (a.k.a. Boriel) <http://www.boriel.com>
66
' ----------------------------------------------------------------
@@ -16,8 +16,8 @@ REM Avoid recursive / multiple inclusion
1616

1717
' ----------------------------------------------------------------
1818
' function ATTR
19-
'
20-
' Parameters:
19+
'
20+
' Parameters:
2121
' row: screen row
2222
' col: screen column
2323
'
@@ -26,6 +26,7 @@ REM Avoid recursive / multiple inclusion
2626
' ----------------------------------------------------------------
2727
function attr(byval row as ubyte, byval col as ubyte) as ubyte
2828
asm
29+
push namespace core
2930

3031
PROC
3132
LOCAL __ATTR_END
@@ -41,8 +42,9 @@ function attr(byval row as ubyte, byval col as ubyte) as ubyte
4142
ld a, (hl) ; byte values are returned in accumulator
4243

4344
__ATTR_END:
44-
ENDP
45+
ENDP
4546

47+
pop namespace
4648
end asm
4749

4850
end function
@@ -51,8 +53,8 @@ end function
5153

5254
' ----------------------------------------------------------------
5355
' sub SETATTR
54-
'
55-
' Parameters:
56+
'
57+
' Parameters:
5658
' row: screen row
5759
' col: screen column
5860
' color: 8bit color attribute
@@ -62,6 +64,7 @@ end function
6264
' ----------------------------------------------------------------
6365
sub setattr(byval row as ubyte, byval col as ubyte, byval value as ubyte)
6466
asm
67+
push namespace core
6568

6669
PROC
6770
LOCAL __ATTR_END
@@ -78,30 +81,33 @@ sub setattr(byval row as ubyte, byval col as ubyte, byval value as ubyte)
7881
ld (hl), a ; "POKE" attr address, color value)
7982

8083
__ATTR_END:
81-
ENDP
84+
ENDP
8285

86+
pop namespace
8387
end asm
8488

8589
end sub
8690

8791

8892
' ----------------------------------------------------------------
8993
' function fastcall ATTRADDR
90-
'
91-
' Parameters:
94+
'
95+
' Parameters:
9296
' row: screen row
9397
' col: screen column
9498
'
9599
' Action: Gets the attribute address of screen(row, column)
96100
' ----------------------------------------------------------------
97101
function fastcall attraddr(byval row as ubyte, byval col as ubyte) as uinteger
98-
asm
99-
; a = row
102+
asm
103+
push namespace core
104+
; a = row
100105
pop hl ; ret address
101106
ex (sp), hl ; Callee => H now has the col
102107
ld d, a ; row
103108
ld e, h
104109
jp __ATTR_ADDR ; Return directly from there
110+
pop namespace
105111
end asm
106112
end function
107113

@@ -115,5 +121,4 @@ end function
115121
' The following is required, because it defines the __IN_SCREEN subroutine.
116122
#require "in_screen.asm"
117123

118-
#endif
119-
124+
#endif

src/arch/zx48k/library/basic.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ REM Avoid recursive / multiple inclusion
4747

4848
Function fastcall EvalBASIC(ByVal basic as String) as Uinteger
4949
ASM
50+
push namespace core
5051
PROC
5152

5253
LOCAL E_LINE
@@ -137,6 +138,7 @@ Function fastcall EvalBASIC(ByVal basic as String) as Uinteger
137138
ld (CH_ADD),hl ;
138139

139140
ENDP
141+
pop namespace
140142
END ASM
141143
End Function
142144

0 commit comments

Comments
 (0)