Welcome, Guest |
You have to register before you can post on our site.
|
Online Users |
There are currently 209 online users. » 0 Member(s) | 207 Guest(s) Bing, Google
|
Latest Threads |
Strange Happenings
Forum: Bug Reports
Last Post: zedex82
6 hours ago
» Replies: 0
» Views: 4
|
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 367
|
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 310
|
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 1,620
|
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 570
|
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 909
|
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 353
|
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 1,077
|
404 page not found
Forum: Documentation
Last Post: boriel
03-08-2025, 07:16 PM
» Replies: 5
» Views: 2,902
|
Spectrum keywords codes
Forum: Bug Reports
Last Post: boriel
03-08-2025, 11:00 AM
» Replies: 1
» Views: 425
|
|
|
ZXB errores mios de sintaxis o incompatible con SinclairBas? |
Posted by: tachuelita - 07-22-2012, 09:17 PM - Forum: ZX Basic Compiler
- Replies (14)
|
 |
Hola a todos, gracias por recibirme en este foro. Sorry por escribir en español, intente' traducir mi texto con el traductor de Google pero confunde mas de lo que explica.
Les cuento que estoy creando un TRACKER para el AY 3-8912 con zx boriel puramente en basic, para poder hacerle Musica y FX a mis juegos, claro que tambien para compartirlo (y aunque alguien me explique como compilar WYZ player, creo que tiene mucho mas mérito para mi, lo tomo como desafio propio).
No es la primera vez que me sucede que alguna rutina no me funciona. Puntualmente en este TOPIC les dejare' las que mas me dieron problema y no entiendo donde esta mi error.
Este "retazo" de rutina funciona con una doble tabla ascii alojada en memoria (50000) brindando 64 columnas a imprimir, para aprovechar mas pantalla. (si, ya se que en LIBRARY del compilador tengo programita que imprime en 64 col, que tampoco se como se usa, pero como dije, a mi me gusta el desafio: "hazlo tu mismo"... tambien se que esta' es bastante precaria a lo basic espectrumero, pero para mejorarla, necesito primero que nada que funcione)
Code: 9550 '------------------------------
'| IMPRIME PATTERN |
'------------------------------
PAUSE 0
BRIGHT 0
FOR f= 0 TO 15
PAPER 7
IF f=0 OR f=4 OR f=8 OR f=12 OR f=16 THEN
PAPER 3
END IF
LET fil = 8 + f
LET col = 1
LET numero = f
LET decimales = 2
GOSUB 9605
NEXT f
STOP
9605 '------------------------------------------------
'\ /
' | INPRESION DE NUMEROS EN 64 COLUMNAS |
'/ \
'------------------------------------------------
'enviar a esta sub rutina:
' fil = fila
' col = columna
' numero
' decimales = 1-unidades
' 2-decenas
' 3-centenas
' 4-mil
' 5-decenas de mil
9606 LET X$=STR$ (numero)
9607 IF decimales > LEN X$ THEN
LET X$="0"+X$
GOTO 9607
END IF
FOR z=0 TO LEN X$ STEP 2
POKE 23607,194
POKE 23606,80
PRINT AT fil,col+(z/2); X$(z)
IF z+1 <= LEN X$ THEN
POKE 23607,197
POKE 23606,80
PRINT AT fil,col+(z/2) ; OVER 1 ; X$(z+1)
END IF
IF z+col > 31 THEN
LET col = 0
LET fil = fil + 1
END IF
NEXT z
POKE 23606,0
POKE 23607,60
RETURN
Aqui les dejo el el .z80 en spectrum basic, el cual funciona a la perfeccion
http://www.mediafire.com/?e1331ilv7wa7k42
el siguiente es el archivo .TAP generado por el compilador del codigo escrito arriba (se resetea)
http://www.mediafire.com/?nubshu8qjaj1kwa
...y el .BIN que debe cargarse en la direccion 50000 con los graficos
http://www.mediafire.com/?fwar9f2ly17hinm
Gracias Boriel por devolverme a la vida, pues programar despierta en mi energias como solo la musica de BACH lo hace; gracias a todos, espero respuestas
|
|
|
FASTCALL warnings |
Posted by: einar - 07-19-2012, 09:43 PM - Forum: Wishlist
- Replies (7)
|
 |
Hi,
Whenever compiling any ZX BASIC program that uses the latest BIFROST* interface library, it will always produce the following warnings:
Code: bifrost.bas:92: warning: FUNCTION 'BIFROSTfindAttr' declared as FASTCALL with 2 parameters
bifrost.bas:177: warning: SUB 'BIFROSTshowTile' declared as FASTCALL with 3 parameters
bifrost.bas:201: warning: SUB 'BIFROSTshowTilePos' declared as FASTCALL with 2 parameters
bifrost.bas:231: warning: SUB 'BIFROSTfillTileAttr' declared as FASTCALL with 3 parameters
In general, these warnings are very useful to notify the user about possible problems on the code. But in the cases when they were already validated (such as above where FASTCALL is used intentionally for performance reasons), they become a disadvantage: the user will always see warnings in every compilation and will soon start to ignore them completely, thus not paying attention anymore to new warnings that may appear about real problems in his/her own code.
I suggest a new directive to allow ignoring such warnings inside an specific library. The idea is that a library file could use something like this:
Code: #pragma push(fastcall_warning)
#pragma fastcall_warning = false
...
#pragma pop(fastcall_warning)
Makes sense?
|
|
|
not sure what it is bug/feature/me |
Posted by: frisian - 06-29-2012, 08:21 PM - Forum: Help & Support
- Replies (2)
|
 |
First something easy I spotted in DRAW.ASM, there are two EQU's that point to the same address
Code: LOCAL __PIXEL_ADDR
__PIXEL_ADDR EQU 22ACh
call __PIXEL_ADDR
and
PIXEL_ADDR EQU 22ACh
one of those two can be removed.
The program I work on I typed in long ago (needless to say it contains typo's in the data) you can find a copy in WOS it's called PIANOLA.
http://www.worldofspectrum.org/infoseeki...id=0008549
In trying to speed up this program i ran into some problems. The program plays music by machine code, the information is transferred by means of reading data into a string. Compiling the hole program is not my intention,
but some drawing and printing to the screen can surly be sped up by compiling that part.
There is a difference in ZX Basic and the Compiler in handling float's in the PLOT and DRAW statements.
It draws 2 figure's with the help of following code
Code: 2030 FOR i=8 TO 215 STEP 207
LET p=30
LET q=0
LET c=COS (14*PI/p)
LET s=SIN (14*PI/p)
PLOT i,132
FOR b=1 TO 30
DRAW INK 1;p,q
LET p=p*c-s*q
LET q=(p*s+q)/c
NEXT b
NEXT i
I converted it into
dim p,q,c,s as float ' need to use float, fixed screws up totally
dim b as byte
dim i as integer
2030 FOR i=8 TO 215 STEP 207
LET p=30
LET q=0
LET c=COS(14*PI/p)
LET s=SIN(14*PI/p)
PLOT i,132+16 ' +16 to get the same position
FOR b=1 TO 30
DRAW INK 1;p,q
LET p=(p*c)-(s*q)
LET q=(p*s+q)/c
NEXT b
NEXT i
Both give a different figure. It took me some days before I figured out that the calculations in the compiled version where correct, converting the float into a integer screwed things up.
1. first add .5 (round off the number)
2. INT must work like in ZX Basic (3.9 gives 3, -3.9 must give -4)
Code: dim p,q,c,s as float
dim b as byte
dim x,y,i as integer
2030 FOR i=8 TO 215 STEP 207
LET p=30
LET q=0
LET c=COS(14*PI/p)
LET s=SIN(14*PI/p)
PLOT i,132+16 ' +16 to get the same position
FOR b=1 TO 30
LET x = INT(p+.5-(p<0)) ' must use strict-bool, works correct in this case because there is never a number+.5 that equals a integer
LET y = INT(q+.5-(q<0))
DRAW INK 1;x,y
LET p=(p*c)-(s*q)
LET q=(p*s+q)/c
NEXT b
NEXT i
This code will give the same figure as ZX Basic.
I think a closer look into how ZX Basic works using float's in PLOT and DRAW and how the are converted to integers is needed
Now my code compiled without error and it's output looked like the normal basic version. The final piece of code.
Code: dim p,q,c,s as float
dim melo,b as byte
dim x,y,i,t as integer
const p1 as byte = 8
border 5
paper 6
2020 CLS
melo = peek (byte,50900) 'if haven't worked out a better place for this yet
PRINT AT 2,7; BRIGHT 1;"WE PROUDLY PRESENT"
PLOT 55,151+16
DRAW 145,0
DRAW 0,9
DRAW -145,0
DRAW 0,-9
DRAW 2,-2
DRAW 145,0
DRAW 0,9
DRAW -2,2
2025 FOR i=7 TO 18
PRINT PAPER 0;AT i,0;" ";AT i,26;" "
NEXT i
PRINT PAPER 0;AT 19,0,,,,,,
2030 FOR i=8 TO 216 STEP 208
LET p=30
LET q=0
LET c=COS(14*PI/p)
LET s=SIN(14*PI/p)
PLOT i,132+16+1
FOR b=1 TO 30
let x = int(p+.5-(p<0))
let y = int(q+.5-(q<0))
DRAW INK 1;x,y
LET p=(p*c)-(s*q)
LET q=(p*s+q)/c
NEXT b
NEXT i
2040 rem LET p=8 'rename p to p1 and made it a constant
PRINT OVER 1;AT 18,6;"\..\..\..";AT 18,23;"\..\..\.."; INK 2;AT 6,0;"\..\..\..\..\..\..";AT 6,26;"\..\..\..\..\..\..";AT 15,0;"\::\::\::\::\::\::";AT 15,26;"\::\::\::\::\::\::";AT 18,9;"\..\..\..\..\..\..\..\..\..\..\..\..\..\.."
2045 FOR i=1 TO 5
let h$=" "
let f$=" "
if i=3 then let h$="BACH" : let f$="BEAT" : end If
if i=5 then let h$=" " : let f$=" " : end if
PRINT OVER 1; BRIGHT 1; INK p1; PAPER 4;AT i,1+(i=5);h$;AT i,27+(i=5);f$
next i
2050 PLOT 204,28+16
DRAW 0,104
PLOT 207,28+16
DRAW 0,104
DRAW -80,0,.3
DRAW -79,0,.3
DRAW 0,-104
PLOT 51,28+16
DRAW 0,104
PLOT INK p1;127,28+16
DRAW INK p1;0,104
2055 FOR i=9 TO 15 STEP 2
PRINT AT i,p1;"\e\g \h\g";AT i+1,p1;"\f \g\h \h";AT i,18;"\e \h\h \h";AT i+1,18;"\f\g \g \h"
NEXT i
2060 FOR i=61 TO 141 STEP 80
FOR b=98 TO 50 STEP -16
FOR t=0 TO -p1 STEP -2
PLOT i,b+t+16
DRAW 58,0
NEXT t
DRAW 0,p1
PLOT i,b-p1+16
DRAW 0,p1
NEXT b
NEXT i
2070 PRINT AT 17,9;"= ";melo-1;" =";AT 17,18;"= ";melo-1;" =";AT 20,10; BRIGHT 1; INK 7; PAPER 1;"SPECTRUM&SONS"
2080 PRINT AT 22,0;paper 5;bright 1;"\d \d\d \d\d\d \d\d \d\d\d \d\d \d\d\d \d\d \d\d\d \d\d"; ink 7 ;"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
The compiled piece of code worked but it corrupted something so the running of the normal basic part was not what it should be.
First I load the program, RUN, the program loads the two piece of machine code and runs normal until it returns from the first time it used the compiled code, it then needs to print the title of the music piece on the screen, but here go things wrong, instead it prints what looks likes a piece of listing from the basic program, it seems that some where something is corrupted.
But now comes the weird part, if I BREAK the program and let it RUN without loading the two pieces of machine code, it works as it should with out a problem. :?:
I have tried out something, and found at last the line that causes the problem.
If I REM this line out
PRINT OVER 1; BRIGHT 1; INK p1; PAPER 4;AT i,1+(i=5);h$;AT i,27+(i=5);f$
there is no problem, or replacing f$ and h$ with " " will also work.
The problem seems to be with f$ and h$ or I am doing something wrong. (I rewrite the code, now I know what will work)
Sorry for the somewhat long posting.
Regards
Frisian.
|
|
|
import confusion |
Posted by: slenkar - 06-28-2012, 03:23 AM - Forum: Help & Support
- Replies (4)
|
 |
I like having my pathfinding code in a seperate file,
BUT the pathfinding code has to use an array from main.bas
I get error message saying
identifier 'UnitExists' is a function, not a var
but really its an array
I could put Dim UnitExists in the pathfinding.bas file
but what if another included file needs to reference UnitExists?
UnitExists needs to be 'global' somehow
|
|
|
function INT not working correctly |
Posted by: frisian - 06-20-2012, 09:17 PM - Forum: Bug Reports
- Replies (2)
|
 |
I recently discovered ZX Basis Compiler and this forum and it brought back some memories off the days that i owned and used a ZX Spectrum (48k and later a 128k) . I have collected some emulators over the years so i tried to compile some programs, one off witch made a little drawing using some calculation, it look a little different from the normal basic version.
It comes down to converting a float to a integer.
INT 3.9 gives 3 in normal basic and compiled
INT -3.9 in normal basic this is -4 but compiled the answer is -3
The correct answer is -4 according to the ZX basic manual (and also according other programming languages )
I tried zxb .exe version 1.2.9-s758 and zxb version 1.2.9-s882
this problem also occurrence with CAST(integer,float)
Regards
|
|
|
Random Functions |
Posted by: britlion - 06-18-2012, 11:07 PM - Forum: How-To & Tutorials
- Replies (6)
|
 |
Boriel has included a better random function in the code; but this passes through floating point numbers, which is potentially fairly slow - and for games we usually require integer numbers anyway!
I've written a few functions that are a possible alternative.
This is the base function that does the hard work of generating a random number from 0-255 in the A register (or as a return value, conveniently enough). This is the same random number generator that Boriel is using, incidentally. (Based pretty much wholly on Patrik Rak's stream random generator).
Code: FUNCTION FASTCALL randomBase () as uByte
ASM
random: ld hl,$A280 ; xz -> yw
ld de,$C0DE ; yw -> zt
ld (random+1),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 h,l ; y = z
ld l,a ; w = t
ld (random+4),hl
;ret (Not necessary, since the compiler will add ret to the end)
END ASM
END FUNCTION
This function will update the seed value based on the current frames counter. To improve randomness, get the user to have a human interaction that can take a variable amount of time and then run this.
Code: SUB FASTCALL updateSeed()
REM Updates the random generator seed from the FRAMES system variable.
t()
ASM
LD A,E
EX DE,HL
LD HL,random+2
XOR (HL)
AND A
JR NZ,updateSeedNotZero
INC A
updateSeedNotZero:
LD (HL),A
LD HL,random+4
LD A,E
XOR (HL)
LD (HL),A
INC HL
LD A,D
XOR (HL)
LD (HL),A
END ASM
END SUB
The above function depends on my timer function, which gets the value in FRAMES:
Code: FUNCTION FASTCALL t() as uLong
asm
DI
LD DE,(23674)
LD D,0
LD HL,(23672)
EI
end asm
end function
This function returns a value from zero to the specified limit number (limit <= 255)
Code: FUNCTION fastcall randomBin(limit as uByte) as uByte
ASM
AND A
RET Z ; Input zero, output zero.
LD B,A ; Save A
LD C,255
randomBinLoop:
RLA
JR C, randomBinLoopExit
RR C
JR randomBinLoop ; loop back until we find a bit.
randomBinLoopExit:
randomBinRedoCall:
call random
AND C
CP B
RET Z
JR NC, randomBinRedoCall
END ASM
END FUNCTION
it's worth noting that the issue with this is that it basically rolls a random, and if it's bigger than limit, it rolls another one. This could potentially take a while, and isn't guaranteed to be fast. Though the probability of failing to hit the zone is kept to 50%, so on average it will roll 1.5 random numbers, I think, per call. This should usually be faster than a floating point multiply, I believe.
If you do want a number a random number between 0 and 1, using FIXED is quite a lot faster than float. This routine uses randombase to do that:
Code: FUNCTION FASTCALL randomFixed() as FIXED
ASM
call random
push AF
call random
ld l,A
POP AF
ld h,a
ld d,0
ld e,d
END ASM
END FUNCTION
Timings:
Code: dim time as uLong
DIM n as uInteger
DIM variable as uByte
time=t()
for n=0 to 20000
REM One line of the following three:
'variable=rnd*128
'variable=randomFixed()*128
'variable=randomBin(128)
next n
print t()-time
20,000 loops took:
variable=rnd*128 => 1180 frames.
variable=randomFixed()*128 => 613 Frames (1.92 x faster)
variable=randomBin(128) => 74 frames. (this example is 16 x faster) (worst case averages 13x faster; best case averages 22x faster)
(This does vary by limit, but is never > 89 frames for any limit chosen. Can be as low as about 52. Average is about 64.)
All three, of course, return an integer from 0 to 127 (the last 0-128; this chosen because it's a worse case scenario for timing).
For scale, 20,000 loops calling randomBase takes 37 frames. Of course, this returns a number from 0-255 regardless, with no option to set the upper bound.
|
|
|
Re: DEFB (*solved*) |
Posted by: britlion - 06-16-2012, 03:53 PM - Forum: Bug Reports
- Replies (2)
|
 |
Oh dear.
DEFB 157
DEFB "Man(e;@ "
DEFB 161
test.bas:1001 Error: illegal preprocessor character '@'
Build Failed!
So much for that idea.
|
|
|
|