Welcome, Guest |
You have to register before you can post on our site.
|
Online Users |
There are currently 238 online users. » 0 Member(s) | 235 Guest(s) Applebot, Bing, Google
|
Latest Threads |
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 319
|
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 300
|
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 1,600
|
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 554
|
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 893
|
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 328
|
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 1,066
|
404 page not found
Forum: Documentation
Last Post: boriel
03-08-2025, 07:16 PM
» Replies: 5
» Views: 2,886
|
Spectrum keywords codes
Forum: Bug Reports
Last Post: boriel
03-08-2025, 11:00 AM
» Replies: 1
» Views: 419
|
ZXodus][Engine
Forum: ZX Basic Compiler
Last Post: boriel
02-19-2025, 11:43 PM
» Replies: 69
» Views: 213,808
|
|
|
HOW MUCH MEMORY? ARRAY STRING |
Posted by: JBGV - 03-09-2011, 11:08 AM - Forum: Help & Support
- Replies (1)
|
 |
Hola, I speak English like Tarzan, sorry to write in Spanish: (And an attempt in English with google translator :oops: )
Tengo un par de dudas:
1º Creo recordar que cuando declarábamos una matriz alfanumérica DIM a$(10) sin especificar el tamaño, automáticvamente se reservaba en memoria espacio suficiente para cadenas de 255 caracteres para cada uno de los elementos de la matriz. Eso era un gasto de memoria muy caro, sobre todo para los que no sabemos programar y desperdiciamos memoria en cada línea , por eso limitábamos el tamaño mediante DIM a$(10,20) (por ejemplo) para limitar el tamaño de cada elemento a 20 caracteres.
Usando el compilador la instrucción DIM a$ (10,20) no limita el tamaño de cada elemento ,sino que crea una matriz alfanumerica de 10x20.
La duda es si al declarar la matriz DIM a$(n) AS STRING se está reservando memoria para cadenas de 255 caracteres en los n elementos.
2º El juego que estaba haciendo empezó hacer cosas raras, hasta que me di cuenta que el problema debia ser la falta de memoria (al eliminar arrays de texto el juego volvia a funcionar), ¿como puedo saber cuanta memoria he gastado?, lei que lo que ocupaba el archivo TZX era mas o menos lo que ocupaba el programa, eso es asi?.
--------------
I have a couple of questions:
1º I remember that when we declared an array alphanumeric DIM a $ (10) without specifying the size, automáticvamente reserved memory space for strings of 255 characters for each of the elements of the matrix. That was a very expensive cost of memory, especially for those who do not know programming and wasted memory on each line , so we just kept the size by DIM a $ (10.20) (for example) to limit the size of each item to 20 characters.
Using the compiler instruction DIM to $ (10,20) does not limit the size of each element, but creates an alphanumeric matrix of 10x20.
The question is whether to declare the array DIM a $ (n) AS STRING is allocate memory for strings of 255 characters in the n elements.
2º The game was getting started doing strange things, until I realized that the problem was to be the lack of memory (to delete arrays of text the game was returning to work), how I can know how much memory I have spent?, I read that occupied the TZX file more or less what was occupied by the program, it is so?.
|
|
|
"Illegal Preprocessor" errors on some files (*solved*) |
Posted by: LTee - 03-07-2011, 09:11 AM - Forum: Bug Reports
- Replies (9)
|
 |
For the 1.2.8 test I recompiled all the sources I have kicking around and discovered that a couple won't compile any more. Specifically these are ones containing ASM sections with comments, and they throw an "illegal preprocessor character" error. Curiously the line numbers of the errors don't seem to help much, they seem to point to lines which are blank or ones which don't actually have the character that the preprocessor is complaining about.
This isn't a regression in 1.2.8, by the way - I checked them with 1.2.7 as well and the same problem happens there. Guess I didn't recompile my entire collection of source for a while. :-)
I've included one of the files in full, because I didn't write them so I'm not sure how to cut them down. Apologies. If you need the other one as well then let me know.
Code: SUB dieSound()
DIM n as uByte
FOR n=1 to 2
BEEP rnd/600,9
BEEP rnd/100,(-14-(rnd*5))
PAUSE 1
NEXT n
END SUB
SUB putChars(x as uByte,y as uByte, dataAddress as uInteger)
asm
BLPutChar:
LD a,(IX+5)
ld l,a
ld a,(IX+7)
LD b,a ; save it
AND 24
add a,64 ; 256 byte "page" for screen - 256*64=16384. Change this if you are working with a screen address elsewhere, such as a buffer.
ld h,a
ld a,b ; y value
AND 7
rrca
rrca
rrca
OR l
ld l,a
EX DE,HL
PUSH DE ; save our address
LD L,(IX+8) ; data address
LD H,(IX+9)
EX AF,AF'
LD A,4 ;row counter
EX AF,AF'
BLPutCharLoop:
LD B,8
BLPutCharOneCharLoop:
XOR A; LD A,0
LD C,A
; gets screen address in DE, and bytes address in HL. Copies the row to the screen
LDI ; also decrements B.
LDI
LDI
LDI ; 4 bytes copied.
LD A,C
ADD A,E ;(A should be -4)
LD E,A
INC D
LD A,B
OR A
JP NZ,BLPutCharOneCharLoop
EX AF,AF'
DEC A
JR Z, BLPutCharsEnd ; We've done all 4 rows.
EX AF,AF'
;need to sort our screen address for the next row. Is it right?
LD A,E ; DE has screen address
ADD A,32 ; down to next character
LD E,A
JR C, BLPutCharsCont ; Not in next third.
LD A,D
SUB 8
LD D,A
BLPutCharsCont:
JP BLPutCharLoop
BLPutCharsEnd:
end asm
END SUB
SUB graphicsData()
RETURN
dice:
ASM
; Name : Dice
; Frame : 0
; Size : 32x32
; Palette: ZX Spectrum
; Masked : No
; RowOrder: Classic
end asm
Dice000:
asm
; pixels and mask bit pairs
defb 1, 83, 48, 0
defb 3, 83, 14, 0
defb 6, 200, 67, 0
defb 4, 200, 97, 128
defb 12, 136, 96, 96
defb 8, 4, 32, 24
defb 24, 4, 8, 4
defb 16, 4, 140, 4
defb 16, 2, 14, 4
defb 32, 7, 3, 0
defb 64, 12, 64, 2
defb 64, 8, 96, 2
defb 128, 24, 24, 2
defb 128, 18, 6, 96
defb 0, 51, 1, 249
defb 128, 35, 192, 241
defb 128, 67, 128, 57
defb 64, 192, 0, 12
defb 0, 128, 0, 7
defb 68, 158, 0, 33
defb 71, 30, 0, 241
defb 47, 30, 0, 113
defb 14, 8, 0, 243
defb 44, 0, 0, 2
defb 52, 240, 1, 4
defb 24, 240, 7, 136
defb 24, 240, 7, 136
defb 8, 64, 7, 144
defb 6, 0, 0, 0
defb 3, 0, 0, 32
defb 0, 192, 28, 64
defb 0, 112, 60, 64
; Name : Dice
; Frame : 1
; Size : 32x32
; Palette: ZX Spectrum
; Masked : No
; RowOrder: Classic
end asm
Dice001:
asm
; pixels and mask bit pairs
defb 0, 28, 194, 128
defb 0, 49, 194, 128
defb 0, 193, 19, 64
defb 1, 128, 19, 32
defb 14, 0, 5, 32
defb 57, 0, 4, 16
defb 71, 16, 40, 24
defb 183, 48, 32, 8
defb 44, 115, 16, 12
defb 0, 199, 240, 4
defb 0, 15, 48, 130
defb 64, 6, 17, 195
defb 64, 56, 24, 193
defb 4, 225, 72, 193
defb 25, 129, 204, 64
defb 191, 3, 196, 1
defb 188, 33, 194, 1
defb 48, 120, 2, 2
defb 224, 120, 1, 64
defb 132, 120, 1, 98
defb 143, 0, 0, 226
defb 142, 0, 0, 228
defb 207, 0, 0, 96
defb 64, 0, 0, 36
defb 32, 0, 15, 44
defb 48, 0, 15, 24
defb 16, 0, 15, 24
defb 8, 1, 226, 24
defb 8, 1, 224, 120
defb 4, 1, 224, 224
defb 2, 56, 67, 128
defb 2, 60, 12, 0
; Name : Dice
; Frame : 2
; Size : 32x32
; Palette: ZX Spectrum
; Masked : No
; RowOrder: Classic
end asm
Dice002:
asm
; pixels and mask bit pairs
defb 255, 255, 252, 0
defb 192, 0, 2, 0
defb 167, 128, 121, 0
defb 147, 192, 60, 128
defb 136, 0, 0, 64
defb 164, 3, 192, 32
defb 178, 1, 224, 16
defb 177, 0, 0, 8
defb 176, 158, 3, 196
defb 144, 79, 1, 226
defb 128, 63, 255, 255
defb 128, 160, 0, 1
defb 128, 224, 0, 1
defb 128, 227, 12, 49
defb 128, 231, 158, 121
defb 128, 103, 158, 121
defb 128, 35, 12, 49
defb 160, 32, 0, 1
defb 176, 32, 0, 1
defb 176, 32, 0, 1
defb 176, 32, 0, 1
defb 144, 32, 0, 1
defb 64, 32, 0, 1
defb 32, 160, 0, 1
defb 16, 224, 0, 1
defb 8, 227, 12, 49
defb 4, 231, 158, 121
defb 2, 103, 158, 121
defb 1, 35, 12, 49
defb 0, 160, 0, 1
defb 0, 96, 0, 1
defb 0, 63, 255, 255
; Name : Dice
; Frame : 3
; Size : 32x32
; Palette: ZX Spectrum
; Masked : No
; RowOrder: Classic
end asm
Dice003:
asm
; pixels and mask bit pairs
defb 0, 1, 184, 0
defb 0, 26, 14, 0
defb 1, 160, 243, 128
defb 15, 0, 121, 192
defb 30, 224, 16, 112
defb 17, 248, 0, 28
defb 48, 112, 120, 6
defb 32, 52, 60, 131
defb 71, 14, 8, 28
defb 207, 3, 128, 15
defb 135, 0, 220, 0
defb 135, 56, 126, 0
defb 0, 120, 28, 12
defb 0, 56, 6, 192
defb 0, 57, 226, 11
defb 0, 1, 194, 115
defb 0, 1, 230, 22
defb 0, 0, 140, 0
defb 128, 0, 12, 1
defb 192, 0, 16, 1
defb 192, 0, 17, 195
defb 206, 0, 33, 130
defb 14, 0, 35, 4
defb 15, 0, 66, 12
defb 14, 112, 192, 8
defb 192, 112, 224, 24
defb 32, 121, 224, 16
defb 8, 113, 192, 48
defb 6, 3, 64, 160
defb 1, 6, 1, 160
defb 0, 196, 24, 0
defb 0, 125, 128, 0
; Name : Dice
; Frame : 4
; Size : 32x32
; Palette: ZX Spectrum
; Masked : No
; RowOrder: Classic
end asm
Dice004:
asm
; pixels and mask bit pairs
defb 0, 125, 128, 96
defb 1, 196, 24, 32
defb 3, 7, 129, 160
defb 6, 3, 192, 176
defb 24, 113, 193, 48
defb 32, 121, 161, 216
defb 192, 112, 128, 216
defb 0, 80, 192, 232
defb 0, 0, 98, 12
defb 0, 14, 35, 4
defb 192, 15, 49, 130
defb 192, 14, 17, 195
defb 192, 14, 20, 1
defb 128, 0, 14, 1
defb 0, 0, 143, 0
defb 56, 1, 231, 6
defb 56, 1, 194, 3
defb 120, 1, 226, 3
defb 56, 0, 6, 192
defb 0, 0, 28, 40
defb 135, 0, 112, 24
defb 135, 0, 192, 4
defb 207, 3, 0, 15
defb 71, 12, 8, 28
defb 96, 48, 60, 3
defb 48, 124, 120, 6
defb 49, 248, 0, 28
defb 14, 0, 0, 112
defb 15, 0, 1, 192
defb 1, 160, 3, 128
defb 0, 26, 14, 0
defb 0, 1, 184, 0
; Name : Die1
; Size : 32x32
; Palette: ZX Spectrum
; Masked : No
; RowOrder: Classic
end asm
Die1:
asm
; pixels and mask bit pairs
defb 255, 255, 252, 0
defb 192, 0, 2, 0
defb 160, 0, 1, 0
defb 144, 0, 0, 128
defb 136, 0, 0, 64
defb 164, 3, 192, 32
defb 178, 1, 224, 16
defb 177, 0, 0, 8
defb 176, 128, 0, 4
defb 144, 64, 0, 2
defb 128, 63, 255, 255
defb 128, 32, 0, 1
defb 128, 32, 0, 1
defb 128, 35, 0, 49
defb 132, 39, 128, 121
defb 134, 39, 128, 121
defb 134, 35, 0, 49
defb 134, 32, 0, 1
defb 130, 32, 0, 1
defb 128, 32, 12, 1
defb 128, 32, 30, 1
defb 128, 32, 30, 1
defb 64, 32, 12, 1
defb 32, 160, 0, 1
defb 16, 224, 0, 1
defb 8, 227, 0, 49
defb 4, 231, 128, 121
defb 2, 103, 128, 121
defb 1, 35, 0, 49
defb 0, 160, 0, 1
defb 0, 96, 0, 1
defb 0, 63, 255, 255
; Name : Die2
; Size : 32x32
; Palette: ZX Spectrum
; Masked : No
; RowOrder: Classic
end asm
Die2:
asm
; pixels and mask bit pairs
defb 255, 255, 252, 0
defb 192, 0, 2, 0
defb 167, 128, 1, 0
defb 147, 192, 0, 128
defb 136, 0, 0, 64
defb 164, 0, 0, 32
defb 178, 0, 0, 16
defb 177, 0, 0, 8
defb 176, 128, 3, 196
defb 144, 64, 1, 226
defb 128, 63, 255, 255
defb 160, 160, 0, 1
defb 176, 224, 0, 1
defb 176, 227, 0, 49
defb 176, 231, 128, 121
defb 144, 103, 128, 121
defb 128, 35, 0, 49
defb 160, 160, 0, 1
defb 176, 224, 0, 1
defb 176, 224, 0, 1
defb 176, 224, 0, 1
defb 144, 96, 0, 1
defb 64, 32, 0, 1
defb 32, 160, 0, 1
defb 16, 224, 0, 1
defb 8, 227, 0, 49
defb 4, 231, 128, 121
defb 2, 103, 128, 121
defb 1, 35, 0, 49
defb 0, 160, 0, 1
defb 0, 96, 0, 1
defb 0, 63, 255, 255
; Name : Die3
; Size : 32x32
; Palette: ZX Spectrum
; Masked : No
; RowOrder: Classic
end asm
Die3:
asm
; pixels and mask bit pairs
defb 255, 255, 252, 0
defb 192, 0, 2, 0
defb 167, 128, 1, 0
defb 147, 192, 0, 128
defb 136, 0, 0, 64
defb 164, 3, 192, 32
defb 178, 1, 224, 16
defb 177, 0, 0, 8
defb 176, 128, 1, 228
defb 144, 64, 0, 242
defb 128, 63, 255, 255
defb 128, 160, 0, 1
defb 128, 224, 0, 1
defb 128, 224, 0, 1
defb 132, 224, 0, 1
defb 134, 96, 0, 1
defb 134, 32, 0, 1
defb 166, 32, 0, 1
defb 178, 32, 0, 1
defb 176, 32, 12, 1
defb 176, 32, 30, 1
defb 144, 32, 30, 1
defb 64, 32, 12, 1
defb 32, 160, 0, 1
defb 16, 224, 0, 1
defb 8, 224, 0, 1
defb 4, 224, 0, 1
defb 2, 96, 0, 1
defb 1, 32, 0, 1
defb 0, 160, 0, 1
defb 0, 96, 0, 1
defb 0, 63, 255, 255
; Name : Die4
; Size : 32x32
; Palette: ZX Spectrum
; Masked : No
; RowOrder: Classic
end asm
Die4:
asm
; pixels and mask bit pairs
defb 255, 255, 252, 0
defb 192, 0, 2, 0
defb 167, 128, 121, 0
defb 147, 192, 60, 128
defb 136, 0, 0, 64
defb 164, 0, 0, 32
defb 178, 0, 0, 16
defb 177, 0, 0, 8
defb 176, 158, 3, 196
defb 144, 79, 1, 226
defb 128, 63, 255, 255
defb 160, 160, 0, 1
defb 176, 224, 0, 1
defb 176, 227, 0, 1
defb 176, 231, 128, 1
defb 144, 103, 128, 1
defb 128, 35, 0, 1
defb 160, 160, 0, 1
defb 176, 224, 0, 1
defb 176, 224, 0, 1
defb 176, 224, 0, 1
defb 144, 96, 0, 1
defb 64, 32, 0, 1
defb 32, 160, 0, 1
defb 16, 224, 0, 1
defb 8, 224, 0, 49
defb 4, 224, 0, 121
defb 2, 96, 0, 121
defb 1, 32, 0, 49
defb 0, 160, 0, 1
defb 0, 96, 0, 1
defb 0, 63, 255, 255
; Name : Die5
; Size : 32x32
; Palette: ZX Spectrum
; Masked : No
; RowOrder: Classic
end asm
Die5:
asm
; pixels and mask bit pairs
defb 255, 255, 252, 0
defb 192, 0, 2, 0
defb 167, 128, 121, 0
defb 147, 192, 60, 128
defb 136, 0, 0, 64
defb 132, 3, 192, 32
defb 130, 1, 224, 16
defb 129, 0, 0, 8
defb 128, 158, 3, 196
defb 128, 79, 1, 226
defb 128, 63, 255, 255
defb 128, 32, 0, 1
defb 128, 32, 0, 1
defb 128, 35, 0, 1
defb 132, 39, 128, 1
defb 134, 39, 128, 1
defb 134, 35, 0, 1
defb 134, 32, 0, 1
defb 130, 32, 0, 1
defb 128, 32, 12, 1
defb 128, 32, 30, 1
defb 128, 32, 30, 1
defb 64, 32, 12, 1
defb 32, 32, 0, 1
defb 16, 32, 0, 1
defb 8, 32, 0, 49
defb 4, 32, 0, 121
defb 2, 32, 0, 121
defb 1, 32, 0, 49
defb 0, 160, 0, 1
defb 0, 96, 0, 1
defb 0, 63, 255, 255
; Name : Die6
; Size : 32x32
; Palette: ZX Spectrum
; Masked : No
; RowOrder: Classic
end asm
Die6:
asm
; pixels and mask bit pairs
defb 255, 255, 252, 0
defb 192, 0, 2, 0
defb 167, 128, 121, 0
defb 147, 192, 60, 128
defb 136, 0, 0, 64
defb 164, 240, 15, 32
defb 178, 120, 7, 144
defb 177, 0, 0, 8
defb 176, 158, 3, 196
defb 144, 79, 1, 226
defb 128, 63, 255, 255
defb 128, 160, 0, 1
defb 128, 224, 0, 1
defb 128, 227, 0, 49
defb 128, 231, 128, 121
defb 128, 103, 128, 121
defb 128, 35, 0, 49
defb 160, 32, 0, 1
defb 176, 32, 0, 1
defb 176, 32, 12, 1
defb 176, 32, 30, 1
defb 144, 32, 30, 1
defb 64, 32, 12, 1
defb 32, 160, 0, 1
defb 16, 224, 0, 1
defb 8, 227, 0, 49
defb 4, 231, 128, 121
defb 2, 103, 128, 121
defb 1, 35, 0, 49
defb 0, 160, 0, 1
defb 0, 96, 0, 1
defb 0, 63, 255, 255
end asm
blank:
asm
blank:
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
defb 0, 0, 0, 0
END ASM
END SUB
REM Initialize Everything
graphicsData()
DIM diceFrames(3) AS uInteger
diceFrames(0)=@Dice000
diceFrames(1)=@Dice001
diceFrames(2)=@Dice002
diceFrames(3)=@Dice003
DIM diceSprites(5) AS uInteger
diceSprites(0)=@Die1
diceSprites(1)=@Die2
diceSprites(2)=@Die3
diceSprites(3)=@Die4
diceSprites(4)=@Die5
diceSprites(5)=@Die6
FUNCTION rollDice(x as uByte, y as uByte) as uByte
DIM roll,frames,i as uByte
roll = INT(RND*6) : REM Rolls 0-5 for animation.
frames=INT(rnd*6)+4
FOR i=1 to frames
dieSound()
asm
HALT
end asm
IF(x+i)<>0 then putChars(x+i-1,y,@blank) : END IF
IF i MOD 5 =0 then putChars(x+i,y,diceSprites(rnd*6))
ELSE putChars(x+i,y,diceFrames((i mod 5)-1))
END IF
NEXT i
PAUSE 1
putChars(x+i-1,y,@blank)
putChars(x+i,y,diceSprites(roll))
return roll+1
END FUNCTION
print rollDice(0,0)
print rollDice(15,0)
On a possibly-related note, I've discovered that Print42.bas no longer compiles in 1.2.7/1.2.8. That gives the following error:
Code: Print42.bas:390: Error: Syntax error. Unexpected token 'DEFB' [DEFB]
|
|
|
Collision attr routine. |
Posted by: compiuter - 03-06-2011, 10:50 PM - Forum: Wishlist
- Replies (7)
|
 |
I was thinking about any routines that get attr positions up, right, down and left for one character of x,y position.
-p-
qAr
-s-
And the same for a tile
-pq-
rABt
sCDu
-vw-
and poke those valours into printer buffer or into a variable address, etc.
I'm tired for repeat the same sentences IF ATTR in basic listing cause is a heavy job.
I have no time now, but if someone has free time for this and they want...
I think this can be a library called e.g. ATTTR.bas or ATTTR.asm
Thx.
|
|
|
New beta release 1.2.8r2121 |
Posted by: boriel - 03-06-2011, 02:08 PM - Forum: Bug Reports
- Replies (1)
|
 |
Okay, this starts a new life cicle. Release 1.2.8x
At the moment it's just like 1.2.7 but with some code refactoring (no new features). Test is needed as it should behave exactly the same as previous versions (currently more than 40 tests proves so).
Download here:
<!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Archive#Latest_Development_Version">http://www.boriel.com/wiki/en/index.php ... nt_Version</a><!-- m -->
|
|
|
Optimiser -o3 bug found (*solved*) |
Posted by: LCD - 03-04-2011, 08:39 PM - Forum: Bug Reports
- Replies (4)
|
 |
Hi Boriel,
I have found a bug with -o3 optimiser (-o2 works well)
In following code (not fully finished yet) in -o3 mode not all chess Figures are displayed. The figures are named in german as they are just placeholders for graphics that will be added later.
Oh, just noticed that also the binary operator shortcuts (|, &, ...) are not working too (yet).
Code: ' Blind King (c) 2010 By LCD, written using BorIDE and ZXBC
FUNCTION attrAddress(x as uByte, y as uByte) as uInteger
';; This function returns the memory address of the Character Position
';; x,y in the attribute screen memory.
';; Adapted from code by Jonathan Cauldwell - Adapted for ZX BASiC by Britlion from Na_TH_AN's fourspriter
asm
ld a,(IX+7) ;ypos
rrca
rrca
rrca ;' Multiply by 32
ld l,a ;' Pass to L
and 3 ;' Mask with 00000011
add a,88 ;' 88 * 256 = 22528 - start of attributes.
ld h,a ;' Put it in the High Byte
ld a,l ;' We get y value *32
and 224 ;' Mask with 11100000
ld l,a ;' Put it in L
ld a,(IX+5) ;' xpos
add a,l ;' Add it to the Low byte
ld l,a ;' Put it back in L, and we're done. HL=Address.
end asm
END FUNCTION
FUNCTION scrAddress(x as uByte, y as uByte) as Uinteger
asm
;' This fn returns the address into HL of the screen address
;' x,y in character grid notation.
;' Original code was extracted by BloodBaz - Adapted for ZX BASiC by Britlion from Na_TH_AN's fourspriter
; x Arrives in A, y is in stack.
and 31
ld l,a
ld a,(IX+7) ; Y value
ld d,a
and 24
add a,64
ld h,a
ld a,d
and 7
rrca
rrca
rrca
or l
ld l,a
end asm
END FUNCTION
sub putblock(x as Ubyte,y as ubyte,wid as ubyte,hgt as ubyte,adr as Uinteger)
dim scr,attribute as Uinteger
dim x1,y1 as Ubyte
dim a as Ubyte
poke uinteger @putblock1+7,wid
poke uinteger @putblock2+7,wid
for y1=0 to hgt-1
scr=scrAddress(x,y+y1)
for a=0 to 7
poke uinteger @putblock1+1,adr
poke uinteger @putblock1+4,scr
putblock1:
asm
ld hl,1
ld de,2
ld bc,3
ldir
end asm
adr=adr+wid
scr=scr+256
next a
next y1
attribute=attrAddress(x,y)
for y1=0 to hgt-1
poke uinteger @putblock2+1,adr
poke uinteger @putblock2+4,attribute
adr=adr+wid
attribute=attribute+32
putblock2:
asm
ld hl,4
ld de,5
ld bc,6
ldir
end asm
next y1
End sub
function ScanField(x as integer,y as integer,mask as ubyte) as ubyte
if x>=0 and x<8 and y>=0 and y<8 then
adr=@overlay+(y<<3)+x
return peek adr band mask
Else
return 0
end if
end function
sub SetField(x as uinteger,y as uinteger,fig as ubyte)
dim adr as uinteger
adr=@overlay+(y<<3)+x
poke adr,(peek adr) bor fig
end sub
function ScanDiagonal(x as ubyte,y as ubyte) as ubyte
dim dist,found,d1,d2,d3,d4 as ubyte
while found=0
end while
'This scans diagonal fields from x,y until figure or end of field for queen or bishop
end Function
function ScanStraight(x as ubyte,y as ubyte) as ubyte
'This scans straight fields until figure or end of field for queen or rook
end Function
function ScanNear(x as ubyte,y as ubyte) as ubyte
'This scans next fields of x,y until figure for king or pawn
dim result as ubyte
if ScanField(x-1,y-1,7)=1 or ScanField(x+1,y-1,7)=1 then result=1:end if
if ScanField(x-1,y-1,7)=6 or ScanField(x,y-1,7)=6 or ScanField(x+1,y-1,7)=6 or ScanField(x-1,y,7)=6 or ScanField(x+1,y,7)=6 or ScanField(x-1,y+1,7)=6 or ScanField(x,y+1,7)=6 or ScanField(x+1,y+1,7)=6 then result=result bor 32:end if
return result
end Function
function ScanKnight(x as ubyte,y as ubyte) as ubyte
'This scans field x,y if attacked by knight
dim result as ubyte
if ScanField(x-1,y-2,7)=3 or ScanField(x+1,y-2,7)=3 or ScanField(x-1,y+2,7)=3 or ScanField(x+1,y+2,7)=3 or ScanField(x-2,y-1,7)=3 or ScanField(x+2,y-1,7)=3 or ScanField(x-2,y+1,7)=3 or ScanField(x+2,y+1,7)=3 then result=3:end if
return result
end Function
function ScanFields(x as ubyte,y as ubyte) as ubyte
'This scans all fields, first: diagonal for queen or bishop until figure or end of field
print at 0,24;ScanNear(x,y);" ";
print at 1,24;ScanKnight(x,y);" ";
end Function
paper 0:ink 6:bright 1:flash 0:border 2:cls
'print at 0,0;"\{i7}\{p1}Blind King 2010 By LCD"
dim x,y,x1,y1,col,a,left,posx,posy as ubyte
dim scr,adr as uinteger
print at 23,0;"Press any key to start battle"
pause 0
randomize
cls
adr=@chessboard
for y=0 to 7
for x=0 to 7
col=peek(adr)
for y1=0 to 2
scr=attrAddress(x*3,y*3+y1)
poke scr,col:poke scr+1,col:poke scr+2,col
next y1
adr=adr+1
next x
next y
' Setup field
left=8 'Bauern
while left>0
x=int(rnd*7.9999)
y=int(rnd*6.9999)
if ScanField(x,y,7)=0 then
SetField(x,y,1)
left=left-1
end If
end while
left=2 'Türme
while left>0
x=int(rnd*7.9999)
y=int(rnd*6.9999)
if ScanField(x,y,7)=0 then
SetField(x,y,2)
left=left-1
end If
end while
left=2 'Springer
while left>0
x=int(rnd*7.9999)
y=int(rnd*6.9999)
if ScanField(x,y,7)=0 then
SetField(x,y,3)
left=left-1
end If
end while
left=2 'Läufer
while left>0
x=int(rnd*7.9999)
y=int(rnd*6.9999)
if ScanField(x,y,7)=0 then
SetField(x,y,4)
left=left-1
end If
end while
left=1 'Dame
while left>0
x=int(rnd*7.9999)
y=int(rnd*6.9999)
if ScanField(x,y,7)=0 then
SetField(x,y,5)
left=left-1
end If
end while
left=1 'König
while left>0
x=int(rnd*7.9999)
y=int(rnd*6.9999)
if ScanField(x,y,7)=0 then
SetField(x,y,6)
left=left-1
end If
end while
' Display field (test)
for y=0 to 7
for x=0 to 7
a=ScanField(x,y,7)
x1=x*3+1
y1=y*3+1
if a=1 then print at y1,x1;"B";:end If
if a=2 then print at y1,x1;"T";:end If
if a=3 then print at y1,x1;"S";:end If
if a=4 then print at y1,x1;"L";:end If
if a=5 then print at y1,x1;"D";:end If
if a=6 then print at y1,x1;"K";:end If
next x
next y
posx=7:posy=7
Mainloop:
x1=posx*3+1
y1=posy*3+1
print at y1,x1;"F";
if inkey$="o" and posx>0 then print at y1,x1;" ";:posx=posx-1:ScanFields(posx,posy):end if
if inkey$="p" and posx<7 then print at y1,x1;" ";:posx=posx+1:ScanFields(posx,posy):end if
if inkey$="q" and posy>0 then print at y1,x1;" ";:posy=posy-1:ScanFields(posx,posy):end if
if inkey$="a" and posy<7 then print at y1,x1;" ";:posy=posy+1:ScanFields(posx,posy):end if
goto Mainloop
'pause 0
End
chessboard:
asm
defb 32,64,32,64,32,64,32,64
defb 64,32,64,32,64,32,64,32
defb 32,64,32,64,32,64,32,64
defb 64,32,64,32,64,32,64,32
defb 32,64,32,64,32,64,32,64
defb 64,32,64,32,64,32,64,32
defb 32,64,32,64,32,64,32,64
defb 64,32,64,32,64,32,64,32
end asm
overlay:
'0=Leer
'1=Bauer
'2=Turm
'3=Springer
'4=Läufer
'5=Königin
'6=König
'+128=hidden
'+64=White field
'+32=Black field
asm
defb 56,80,56,80,56,80,56,80
defb 80,56,80,56,80,56,80,56
defb 56,80,56,80,56,80,56,80
defb 80,56,80,56,80,56,80,56
defb 56,80,56,80,56,80,56,80
defb 80,56,80,56,80,56,80,56
defb 56,80,56,80,56,80,56,80
defb 80,56,80,56,80,56,80,56
end asm
|
|
|
Returning a String from a function |
Posted by: LTee - 03-03-2011, 04:57 PM - Forum: Help & Support
- Replies (9)
|
 |
Hi all!
Is it possible to return a string from a function? I tried this:
Code: dim result as STRING
result = test(50)
print result
function test(n as UBYTE) as STRING
return str(n)
end function
But I get a compile error:
Code: test.bas:2: Cannot convert value to string. Use STR() function
Am I doing something wrong? I'm suspecting the answer is 'yes'. :-)
|
|
|
-d (display debug info) not working? |
Posted by: LCD - 02-28-2011, 11:14 PM - Forum: Bug Reports
- Replies (7)
|
 |
Hi Boriel. Maybe it is a bug... If I try to use -d option for displaying debug info, the compiler enters a infinite loop. Is it not supported anymore in build 2114?
Ah, the program is a simple PRINT "Hallo", nothing else.
|
|
|
Version 1.2.7 released! |
Posted by: boriel - 02-26-2011, 10:42 PM - Forum: ZX Basic Compiler
- Replies (2)
|
 |
Okay, finally version 1.2.7 is out (revision 2114).
It's a major refactorization of the zxbpp and zxbasmpp (the preprocessors).
Check the changelog if interested. Basically, main changes are: - + DRAW is now much faster (and a bit more larger)
- + PLOT, DRAW and CIRCLE now supports change screen address (for double-buffering)
- + Added LBOUND() and UBOUND() functions
- ! Fixed a bug in IF/THEN/ELSEIF/ELSE construct (thanks to LTee)
- + Added a completely new preprocessor which now support true macros and
better line counting handling. This has been a major change in the compiler.
- + Added string management library with
UCase(), LCase(), Ucase2(), LCase2(), InStr() and StrPos()
- ! UDG where not being handled into the Heap, which might lead to program
crash (fixed). This is done only if --sinclair or -Z flag is used.
- + Added suport for BIN, so BIN 01010101 is also accepted now.
- ! Fixed a bug with string parameters passed by value (again) not being correctly
free upon return and crashing the program.
- + BEEP with constant duration and pitch (e.g. BEEP 1, 2) has been
optimized for space (and also slightly faster)
- + Added Flight Simulator example
You can download it at <!-- m --><a class="postlink" href="http://www.boriel.com/files/zxb">http://www.boriel.com/files/zxb</a><!-- m --> (will redirect you to the archive).
Legacy version 1.2.6 will also remain there. :wink:
|
|
|
UBYTE/FOR loop issue? |
Posted by: LTee - 02-25-2011, 01:07 PM - Forum: Help & Support
- Replies (4)
|
 |
I wrote the following code to list out the numbers from 0 to 255:
Code: DIM i as UBYTE = 0
for i = 0 to 255
print i;" "
next i
The code compiles and runs, but it never ends. When the loop gets to 255, it begins again from 0. :-)
Making the loop "0 to 254" or changing i to an INTEGER/UINTEGER gets around the issue.
|
|
|
Pass an array as a parameter? |
Posted by: LTee - 02-24-2011, 02:46 PM - Forum: Help & Support
- Replies (3)
|
 |
A question today, rather than a bug. :-)
Is it possible to pass an array as a parameter to a function or a sub?
And if so, does the function/sub receive a copy of the array or a pointer to the original? i.e. if I made changes to the array within a function, would those changes be local to the function or would they also be visible from the calling method?
|
|
|
|