Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 269
» Latest member: Josephcew
» Forum threads: 1,075
» Forum posts: 6,435

Full Statistics

Online Users
There are currently 136 online users.
» 0 Member(s) | 132 Guest(s)
Applebot, Bing, Google, Yandex

Latest Threads
Strange Happenings
Forum: Bug Reports
Last Post: zedex82
05-07-2025, 09:05 AM
» Replies: 0
» Views: 40
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 420
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 333
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 1,662
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 603
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 936
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 373
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 1,135
404 page not found
Forum: Documentation
Last Post: boriel
03-08-2025, 07:16 PM
» Replies: 5
» Views: 2,920
Spectrum keywords codes
Forum: Bug Reports
Last Post: boriel
03-08-2025, 11:00 AM
» Replies: 1
» Views: 438

 
  sub and function, asm and ix
Posted by: nitrofurano - 06-10-2013, 02:22 PM - Forum: Help & Support - No Replies

when advancing a bit more on the MSX part of Boriel's ZX-Basic Compiler, and after that help from accessing paged memory on ZX-Spectrum 128k, i got this situation:

the library i used on the MSX "version"

Code:
sub msxvpoke(tad as uinteger,tva as uinteger)
  asm
    ld h,(ix+5)
    ld l,(ix+4)
    ld a,(ix+6)
    call $004D
    end asm
  end sub

there i'm seeing that sub is using 'ix' from the arguments, but i don't know how are they arranged (as ubyte, uinteger, etc.), and why or what for we use fastcall, get ix instead of bc,de,hl,af - and from a function, in which register or index the value is returned (af, just like from fastcall?)

i can't find documentation explaining it better on the wiki: <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:FUNCTION">http://www.boriel.com/wiki/en/index.php ... C:FUNCTION</a><!-- m --> and <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:SUB">http://www.boriel.com/wiki/en/index.php/ZX_BASIC:SUB</a><!-- m -->

thanks and cheers! Smile

Print this item

  zxbasic for dos?
Posted by: slenkar - 05-29-2013, 06:00 PM - Forum: Wishlist - Replies (10)

Would it be easier to create a script to translate zxbasic to C, or to write a compiler target for x86 asm?

Print this item

  128k memory paging, how can we do that? :S
Posted by: nitrofurano - 05-29-2013, 12:55 PM - Forum: Help & Support - Replies (11)

hi everyone!
based on the information i found at <!-- m --><a class="postlink" href="http://www.worldofspectrum.org/faq/reference/128kreference.htm">http://www.worldofspectrum.org/faq/refe ... erence.htm</a><!-- m -->

i tried this one:

Code:
cls
page1=0
a=(((peek($5B5C))band $F8)bor (page1 band 7))
poke $5B5C,a:out $7FFD,a
poke $C123,80
page1=1
a=(((peek($5B5C))band $F8)bor (page1 band 7))
poke $5B5C,a:out $7FFD,a
poke $C123,81
page1=0
a=(((peek($5B5C))band $F8)bor (page1 band 7))
poke $5B5C,a:out $7FFD,a
print peek($C123)
page1=1
a=(((peek($5B5C))band $F8)bor (page1 band 7))
poke $5B5C,a:out $7FFD,a
print peek($C123)
pause 0

and i can't figure out what is going wrong there...- any clue? :S

Print this item

  Scrolling Tiles
Posted by: slenkar - 05-21-2013, 04:56 PM - Forum: How-To & Tutorials - Replies (10)

I managed to get it done using ZXBASIC

Code:
DIM mapdata(31) AS UBYTE => {1,0,2,0,2,1,1,2,1,0,2,0,2,1,1,2,1,0,2,0,2,1,1,2,1,0,2,0,2,1,1,2}
DIM brick(7) AS UBYTE =>{249,249,0,159,159,0,249,249}
DIM crystal(7) AS UBYTE =>{16,40,84,40,84,40,16,0}

Dim CurrentGraphic as ubyte=1
Dim NextGraphic as Ubyte
Dim PreviousGraphic as ubyte

Dim address as UInteger
Dim LineStartAddress as UInteger
addr=16384
LineStartAddress=addr
Dim PreviousAddress as UInteger

Dim LandscapeEightIter as Ubyte
Dim LandscapeIter as ubyte
Dim LineNumber as UByte

for x=0 to 31
Print AT 0,x;"["
next

for iterations=0 to 258 'scroll left 258 times
address=16384

for y=0 to 7
LineStartAddress=address


for x=0 to 31
CurrentGraphic = PEEK(address)
'pause 5


if x>0 'the leftmost byte has no graphics to its left
if CurrentGraphic Band 128=128 'if this graphic has a dot on the left
PreviousGraphic=PreviousGraphic Bor 1 'Add a dot to the right of the previous graphic byte
POKE PreviousAddress,PreviousGraphic
end if
end if

PreviousAddress=address 'save the address of the byte on the left
CurrentGraphic=CurrentGraphic SHL 1 'shift dors to left
PreviousGraphic=CurrentGraphic 'save graphic

if x<31
POKE address,CurrentGraphic
end if

if x=31

if mapdata(LandscapeIter)=1
NextGraphic=brick(LineNumber)
end if

if mapdata(LandscapeIter)=2
NextGraphic=crystal(LineNumber)
end if

if mapdata(LandscapeIter)=0
NextGraphic=0
end if



if LandscapeEightIter=0
if NextGraphic Band 1=1
CurrentGraphic=CurrentGraphic BOR 1
end if
end if

if LandscapeEightIter=1
if NextGraphic Band 2=2
CurrentGraphic=CurrentGraphic BOR 1
end if
end if

if LandscapeEightIter=2
if NextGraphic Band 4=4
CurrentGraphic=CurrentGraphic BOR 1
end if
end if

if LandscapeEightIter=3
if NextGraphic Band 8=8
CurrentGraphic=CurrentGraphic BOR 1
end if
end if

if LandscapeEightIter=4
if NextGraphic Band 16=16
CurrentGraphic=CurrentGraphic BOR 1
end if
end if

if LandscapeEightIter=5
if NextGraphic Band 32=32
CurrentGraphic=CurrentGraphic BOR 1
end if
end if

if LandscapeEightIter=6
if NextGraphic Band 64=64
CurrentGraphic=CurrentGraphic BOR 1
end if
end if

if LandscapeEightIter=7
if NextGraphic Band 128=128
CurrentGraphic=CurrentGraphic BOR 1
end if
end if

POKE address,CurrentGraphic

end if

address=address+1 'move one square right
next
address=LineStartAddress
address=address+256 'move one line down
LineNumber=LineNumber+1

next
LineNumber=0

LandscapeEightIter=LandscapeEightIter+1
if LandscapeEightIter=8
LandscapeEightIter=0
LandscapeIter=LandscapeIter+1
end if

next

Print "done"
Print STR(178 Band 128)
STOP

but I could never get it done using assembly:
Code:
function FASTCALL drawthis() as ubyte
asm


;LD HL,2000
;LD (delayiter),HL
LD HL,16384

;drawvert:
;LD A,31
;LD L,A
;LD (screenwidthiter),A

;drawblokes:

;LD A,(graphic)
;DEC A
;LD (graphic),A
;LD (HL),A






;LD A,(screenwidthiter)
;LD L,A
;DEC A
;LD (screenwidthiter),A
;LD B,A
;INC B
;INC B
;INC B
;djnz drawblokes

;LD A,(screenheightiter)
;LD L,A
;INC H
;DEC A
;LD (screenheightiter),A
;LD B,A

;INC B
;djnz drawvert




LD A,31
LD (screenwidthiter),A
LD A,7
LD (screenheightiter),A

LD HL,60000
LD (delayiter),HL


loop:
LD BC,20000

LD A,7
LD (screenheightiter),A

LD HL,16384
LD (screenaddress),HL

screenvert:
;LD BC,6000
;wait:
;DEC BC
;LD A,B
;Or C
;jp nz,wait

LD (screenaddress),HL

;load landscape number into a
LD HL,data
LD BC,(landscapeiter)
ADD HL,BC
LD A,(HL)
LD (__LABEL__printablevar),A


;load graphic into B
CP 0
jp z,thisisempty
CP 1
jp z,thisisbrick
CP 2
jp z,thisiscrystal

jp thisisbrick

thisisempty:
LD B,0

jp donegraphic
    
thisisbrick:

LD HL,brick

LD DE,(screenheightiter)
ADD HL,DE
LD B,(HL)

jp donegraphic

thisiscrystal:
LD HL,crystal
LD DE,(screenheightiter)
ADD HL,DE
LD B,(HL)
jp donegraphic

donegraphic:

LD A,0
LD (rightbit),A

LD A,(landscapeiter)


CP 0
jp z,bit0
CP 1
jp z,bit1
CP 2
jp z,bit2
CP 3
jp z,bit3
CP 4
jp z,bit4
CP 5
jp z,bit5
CP 6
jp z,bit6
CP 7
jp z,bit7

bit0:
BIT 0,B
jp nz,setbitfirst
jp z,dontsetbitfirst
bit1:
BIT 1,B
jp nz,setbitfirst
jp z,dontsetbitfirst
bit2:
BIT 2,B
jp nz,setbitfirst
jp z,dontsetbitfirst
bit3:
BIT 3,B
jp nz,setbitfirst
jp z,dontsetbitfirst
bit4:
BIT 4,B
jp nz,setbitfirst
jp z,dontsetbitfirst
bit5:
BIT 5,B
jp nz,setbitfirst
jp z,dontsetbitfirst
bit6:
BIT 6,B
jp nz,setbitfirst
jp z,dontsetbitfirst
bit7:
BIT 7,B
jp z,dontsetbitfirst
jp nz,setbitfirst

setbitfirst:
LD A,1
LD (rightbit),A

dontsetbitfirst:


LD HL,(screenaddress)

LD A,31
LD L,A
LD (screenwidthiter),A
LD (screenaddress),HL

LD A,0
LD (leftbit),A
BIT 7,(HL)
jp nz,dontsetbit
LD A,1
LD (leftbit),A
dontsetbit:


LD A,(HL)
SLA A
LD (HL),A


LD A,(rightbit)
CP 0
jp z, dontsetrightbit
LD A,(HL)
OR 1
LD (HL),A
dontsetrightbit:

LD A,(leftbit)
LD (rightbit),A

LD A,30
LD (screenwidthiter),A
LD L,A
LD (screenaddress),HL


screenhori:


LD A,0
LD (leftbit),A
BIT 7,(HL)
jp nz,dontsetbit3
LD A,1
LD (leftbit),A
dontsetbit3:

LD B,(HL)
SLA B
LD A,(rightbit)
CP 0
jp nz,dontsetblockbit2
LD A,B
OR 1
LD B,A
dontsetblockbit2:
LD (HL),B


LD A,(screenwidthiter)
LD L,A
DEC A
LD (screenwidthiter),A

LD A,(leftbit)
LD (rightbit),A

LD A,(screenwidthiter)
CP 0
jp nz,screenhori



LD A,(screenheightiter)

INC H
DEC A



LD (screenaddress),HL
LD (screenheightiter),A
CP 0
jp nz,screenvert


LD A,(__LABEL__landscapeeightiter)
INC A
LD (__LABEL__landscapeeightiter),A


  

LD A,(__LABEL__landscapeeightiter)
CP 8
jp nz,dontresetblock
LD A,0
LD (__LABEL__landscapeeightiter),A
LD A,(landscapeiter)
INC A
LD (landscapeiter),A
dontresetblock:


;jp loop



end asm
end function

Dim x as Integer

for x=0 to 31
Print AT 0,x;STR(x)
next

for x=0 to 30
drawthis()
Print AT x,0;STR(PEEK(@printablevar))+"-"

next

Print "done"

STOP:
printablevar:
ASM
defb 255
END ASM
landscapeeightiter:
ASM
defb 0
blockiter:
defw 8
delayiter:
defw 60000
screenwidthiter:
defb 31
screenheightiter:
defb 8
scrolliter:
defw 10000
graphic:
defb 255
screenaddress:
defw 0
landscapeiter:
defb 0
data:
defb 1,1,0,1,1,1,0,1,1,2,2,2,2,0,1,0,1,0,2,2,2,2
brick:
defb 249,249,0,159,159,0,249,249
crystal:
defb 16,40,84,40,84,40,16,0
rightbit:
defb 0
leftbit:
defb 0

DISPNUM:
     call 11563      ; We'll push the BC register onto the calculator stack
     call 11747      ; and then output that number to the screen by calling this routine
     ret
end asm

Print this item

  trying to print from assembly
Posted by: slenkar - 05-20-2013, 06:38 PM - Forum: How-To & Tutorials - Replies (3)

this doesnt compile because the label is made outside of ASM tags

Code:
function FASTCALL drawthis() as ubyte
asm
LD A,(landscapeeightiter)
INC A
LD (landscapeeightiter),A    

end asm
end function

for x=0 to 20
drawthis()
Print AT x,0;STR(PEEK(@landscapeeightiter))+"-"
next
STOP
landscapeeightiter:
ASM
defb 100
END ASM

im trying to print the value of the byte at the address, but also modify it in assembly

Print this item

  Assembly question
Posted by: slenkar - 05-12-2013, 05:00 PM - Forum: Help & Support - Replies (27)

In assembly how do you know where to put data?

like say I wanted some arrays how would I know which address in RAM to place the variables?

Is it possible to access arrays created in zxbasic from assembly? how would I do that

Print this item

  Version 1.3.0 Released!
Posted by: boriel - 04-29-2013, 12:46 PM - Forum: ZX Basic Compiler - Replies (6)

ZX Basic 1.3.0 is out! Download it here

NOTE: This is revision 1.3.0s1022
If you already have it, you don't need to download it again.

  • ! Fixed a bug in USR <string>
  • ! Fixed a bug in SAVE / LOAD
  • ! Fixed a serious bug in the preprocessor
  • ! Fixed a bug with DIM and constants
  • ! Fixed a bug with SHL/SHR for 0 shifts
  • + Added -D option. ZXBASIC now allows commandline macro definition
  • ! Fixed a bug with CODE and INKEY$
  • ! Fixed a bug with string slicing assignation (e.g. a$(3) = "x")
  • ! Fixed a bug with arrays of integer assignation (e.g. a(3) = 5, being a of Integer type)
  • ! Fixed a bug with peephole optimizer (-O3)
  • * Some changes and code refactorization towards 2.x branch
...and much much more.

Print this item

  Did I run out of Ram?
Posted by: slenkar - 04-26-2013, 03:42 PM - Forum: Help & Support - No Replies

my pathfinding function worked fine until recently, now it just crashes the spectrum
my wars.rzx file is 28K

EDIT- my mistake!
I was writing out of bounds to an array

Print this item

  How to "localize" (translate) your program
Posted by: boriel - 04-26-2013, 09:12 AM - Forum: How-To & Tutorials - Replies (8)

Yes, we are in the information era, Internet was a dream in the 80s, but a reality nowadays 8)
And we are in sort of Babel tower here. This tutorial proposes a simple but effective way to make your program multilingual.

Needless to say 48Kb (actually less than 40Kb) are too little room to store all localized program texts simultaneously. My proposal is simply a structure to make our programs easily translatable to other languages. Here we go:

ZXBASIC allows commandline defines now (1.2.3-s1022), so it's possible to do something like this:

FILE: LOCALIZE.BAS
This file will include the desired language

Code:
#ifndef LANG
' if no LANG defined, fallback to English as default
#define LANG en
#endif

' Now include the desired file

#if LANG==en
#include <english.bas>
#endif

#if LANG==es
#include <spanish.bas>
#endif

#if LANG==ru
#include <russian.bas>
#endif
The above file will include the desired language definition file.

FILE: ENGLISH.BAS
This defines strings in English, using #define directive
Code:
' Just HELLO WORLD
#define HELLO_WORLD "HELLO WORLD"
FILE: SPANISH.BAS
This defines strings in Spanish, using #define directive
Code:
' Just HELLO WORLD
#define HELLO_WORLD "HOLA MUNDO"
FILE: hello.bas
A demo example, which will be localized.
Code:
#include <localize.bas>

10 REM This is the MAIN code
20 PRINT HELLO_WORLD
Now, to generate for English, compile as:
Code:
zxb -TaB -o hello_en.tzx -D LANG=en hello.bas
To generate the same program translated into Spanish, do:
Code:
zxb -TaB -o hello_es.tzx -D LANG=es hello.bas
NOTICE:
  • Use -o parameter to specify a different output file for each language
    (by default ZX Basic uses just the .bas name, but will replace .bas extension with .tzx or .tap accordingly)
  • Use -D <macro> = <value> to define macro values from the command line.

We all are different native-language speakers here, so if we open-source or .bas listings, some of us would be willing to translate into our mother tongue.

What do you think of this proposal?

Print this item

  ABYDOS
Posted by: JBGV - 04-21-2013, 10:01 PM - Forum: Gallery - Replies (8)

Hola !

This is my new game, if you want to give it a couple of times ...

Hope you like it!



.rar   ABYDOS.rar (Size: 94.56 KB / Downloads: 431)

Print this item