Welcome, Guest |
You have to register before you can post on our site.
|
Online Users |
There are currently 351 online users. » 1 Member(s) | 348 Guest(s) Applebot, Bing, Zoran
|
Latest Threads |
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 231
|
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 269
|
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 1,541
|
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 524
|
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 423
|
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 294
|
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 1,026
|
404 page not found
Forum: Documentation
Last Post: boriel
03-08-2025, 07:16 PM
» Replies: 5
» Views: 2,867
|
Spectrum keywords codes
Forum: Bug Reports
Last Post: boriel
03-08-2025, 11:00 AM
» Replies: 1
» Views: 403
|
ZXodus][Engine
Forum: ZX Basic Compiler
Last Post: boriel
02-19-2025, 11:43 PM
» Replies: 69
» Views: 213,645
|
|
|
Most useful/needed stuff which should be added |
Posted by: na_th_an - 05-28-2010, 10:20 AM - Forum: Wishlist
- Replies (17)
|
 |
This is somewhat a wish list to which I may contribute (coding my second suggestion).
1.- Types. I'm a nightmare, I keep repeating this, but types are most needed. They would make every coding chore way easier, specially when you have to pass parameters or create arrays of structured data. Game coding can be pretty messing without the ability to create proper data structures.
2.- A nice, fast, simple, hassle-less Putchar (x, y, attr, ascii) function which draws character ascii with attributes attr at coordinates (x, y).
3.- Less important, but may come handy, the ability use Attr as a modifier for Print which combines Ink, Bright, Paper, and Flash in a single command:
Code: Print At 2, 2; Attr 71; "Bright white text on black"
4.- A fill routine which allows you to use patterns (for example, a 8x8 pattern defined by a character bitmap).
5.- Allow comments in broken lines, such as this:
Code: Dim myLevel(2) as uByte => { _
0, _ ' Number of exists
10, _ ' Baddies life gauge
7 _ ' Water level
}
Currently, the compiler refuses to compile such snippets. Comments aren't allowed after compiler directives, either, for example:
Code: #include once "fsp2.1.bas" ' The sprite library
Fails to compile due to the inline comment.
As I said, I will probably code a ROM-independent version of "2" and I hope someone makes it properly faster 'cause my ASM is dire. My main problem is that I don't know how to properly interface BASIC/ASM, so it may look cheesy. I'll take a glance at the examples, to see if I can work out how to do it so it's fast and not very ugly. Suggestions?
|
|
|
InLine ASM Bug |
Posted by: LCD - 05-27-2010, 11:23 PM - Forum: Bug Reports
- Replies (5)
|
 |
I have here a Assembly code for Proportional printing (Created by Odin), but zxb throws it out because of a "Unexpected token '-' [MINUS]" at the line "DJNZ Chr_R2Lp2". The compiler tells me the line, but a minus sign is not present here (this is the bug report). Anyway, this could be turned by our friends here into a nice SUB for the library, once it works, I think. It supports pixel precise printing.
I imported it from Tornado source code using my own importer, I wrote for BorIDE.
Code: Asm
; --------------------------------
; Free Size N Place Text Print
; --------------------------------
; (c) 14.09.2002 C.Odenthal
;
; Last Modifications: 15.10.2002
; --------------------------------
; ORG 32000
; DUMP 45000
; --------------------------------
; Entry point
; --------------------------------
Start:
JR Start2
; --------------------------------
; Parameter
; --------------------------------
text_addr:
DEFW test_text ; Addr of text
x_pos:
DEFB 4 ; Pos of text
y_pos:
DEFB 4
spc_size:
DEFB 3 ; Width of space char
x_gap:
DEFB 1 ; Gap between chars
y_gap:
DEFB 1 ; Gap between lines
end_symb:
DEFB 0 ; End of line char code
x_start:
DEFB 0 ; Start of window
y_start:
DEFB 0
x_end:
DEFB 255 ; End of window
y_end:
DEFB 191
x_zoom:
DEFB 1 ; Zooming factor
y_zoom:
DEFB 1
; --------------------------------
; Main routine
; --------------------------------
Start2:
LD A,(x_pos); Calc. scr addr.
LD B,A
LD A,(y_pos)
LD C,A
CALL PosToScr
LD (scr_ad),DE ; Store scr addr.
LD A,L
LD (pix_pos),A
LD A,(end_symb); Get line ending char
LD (poke_here+1),A ; Poke it into memory below
LD HL,(text_addr)
Main_Loop:
LD A,(HL); Get char
poke_here:
CP 0 ; End of text? (poked!)
JP Z,Exit1
INC HL
PUSH HL
CP 32 ; Replace ctrl chars
JP NC,No_Ctrl
LD A,32
No_Ctrl:
CALL Copy_Chr ; Copy char-gfx to work-buffer
CALL Measure ; Measure left rim + width
PUSH BC ; (Save results)
LD A,C ; No pixel set in char?
AND A
JP Z,Space_Chr
LD A,(pix_pos); size+bitpos (=1..15)
ADD A,C
CP 9 ; > 8 ?
JP NC,Overlap ; Char overlaps
; Calculate 8 bit rotation
LD A,(pix_pos) ; bitpos-l_rim (=-7..7)
SUB B
AND A ; = 0 ?
JP Z,PrintIt8
JP C,Neg_8 ; < 0 ?
; --------------------------------
CP 5 ; Not in 1..4 ?
JP NC,Left_8
; --------------------------------
LD B,A
CALL Chr_Rgt8 ; Rotate right 8 bit
JP PrintIt8
; --------------------------------
Left_8:
NEG ; = 8 - A
ADD A,8
LD B,A
CALL Chr_Left8 ; Rotate left 8 bit
JP PrintIt8
; --------------------------------
Neg_8:
NEG
CP 5 ; Not in 1..4 ?
JP NC,Right_8
; --------------------------------
LD B,A
CALL Chr_Left8 ; Rotate left 8 bit
JP PrintIt8
; --------------------------------
Right_8:
NEG ; = 8 - A
ADD A,8
LD B,A
CALL Chr_Rgt8 ; Rotate right 8 bit
JP PrintIt8
; --------------------------------
; Calculate 16 bit rotation
; --------------------------------
Overlap:
LD A,(pix_pos); bitpos-l_rim (=-7..7)
SUB B
AND A ; = 0 ?
JP Z,PrintIt8
; --------------------------------
LD B,A
CALL Chr_Rgt16 ; Rotate right 16 bit
PrintIt16:
LD DE,(scr_ad); Check for screen end
LD A,E
AND 31
CP 31 ; (2nd byte outside ?)
JP Z,Outside
CALL Print16 ; Display char (16 bit)
JP Next_Loc
; --------------------------------
PrintIt8:
LD DE,(scr_ad); Display char (8 bit)
CALL Print8
JP Next_Loc
; --------------------------------
Space_Chr:
LD A,(spc_size); Skip pixels
LD DE,(scr_ad); Get screen addr.
POP BC ; Throw away values
LD B,0
LD C,A
JP Next_Loc2
; --------------------------------
Next_Loc:
POP BC ; Move to next char location
Next_Loc2:
LD A,(pix_pos); =bitpos+x_gap+size
LD L,A
LD A,(x_gap)
ADD A,L
ADD A ,C
LD L ,A
AND 7 ; New pix_pos
LD (pix_pos),A
LD H,0 ; =result/8
SRL L
SRL L
SRL L
ADD HL,DE ; New byte pos
LD A ,E ; Check for screen end
AND 31
LD E,A
LD A,L
AND 31
CP E ; New pos smaller than old ?
JP C ,Exit2 ; -> End of printing
LD (scr_ad),HL ; Store new scr ad.
POP HL ; Restore text pointer
JP Main_Loop
; --------------------------------
Outside:
POP BC ; Stop printing
POP HL ; Char not printed!
DEC HL
JP Exit1
; --------------------------------
Exit2:
POP HL ; Return nr of printed chars
Exit1:
LD DE,(text_addr)
XOR A
SBC HL,DE
LD B,H ; Return value in BC to Basic
LD C,L
RET
; --------------------------------
; --------------------------------
; Calc. scr adr from x,y
; --------------------------------
; In : B = x / C = y (preserved)
; Out: DE = scr adr / L = pixpos
; Usd: A, BC, DE, L
; --------------------------------
PosToScr:
LD A,C ; Range check
CP 185
JP C,ValOk
LD C,184
ValOk:
LD A,B ; Pix pos
AND 7
LD L,A
LD E,B
SRL E
SRL E
SRL E
LD A,C ; Scr pos
AND 7
LD D,A
LD A,C
AND 56
RLA
RLA
OR E
LD E,A
LD A,C
AND 192
RRA
RRA
RRA
OR D
OR 64
LD D,A
RET
; --------------------------------
; Copy char into buffer
; --------------------------------
; In : A = Char
; Out: -
; Usd: A, HL, DE, BC
; --------------------------------
Copy_Chr:
LD DE,(23606); SysVar CHARS
LD H,0
LD L,A
ADD HL,HL ; * 8
ADD HL,HL
ADD HL,HL
ADD HL,DE ; + Chartable
EX DE,HL
LD HL,Chr_Buf
LD B,8
Copy_Loop:
LD A,(DE); Double to 16 pixel/row
INC DE
LD (HL),A ; Low-byte in memory!
INC HL
LD (HL),0 ; High-byte in memory!
INC HL
DJNZ Copy_Loop
RET
; --------------------------------
; Measure left border and width
; --------------------------------
; In : -
; Out: B = left rim / C = width
; Usd: A, HL, BC
; --------------------------------
Measure:
LD HL,Chr_Buf ; "OR" together all 8 bytes
LD B,8
XOR A
Msr_Loop:
OR (HL)
INC HL
INC HL
DJNZ Msr_Loop
LD BC,0
AND A ; Check if zero
RET Z
Msr_Loop2:
INC B ; Measure left border
RLCA
JP NC,Msr_Loop2
RRCA
DEC B
LD C,9 ; Measure width
Msr_Loop3:
DEC C
RRCA
JP NC,Msr_Loop3
RET
; --------------------------------
; Move char to left, 8 bit
; --------------------------------
; In : B = Nr of bits to shift
; Out: -
; Usd: A, B, HL
; --------------------------------
Chr_Left8:
PUSH BC
LD HL,Chr_Buf ; Rotate char left 8 bit
LD C,B ; 1st row
LD A,(HL )
Chr_LLp1:
RLCA
DJNZ Chr_LLp1
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 2nd row
LD A,(HL)
Chr_LLp2:
RLCA
DJNZ Chr_LLp2
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 3rd row
LD A ,(HL)
Chr_LLp3:
RLCA
DJNZ Chr_LLp3
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 4th row
LD A,(HL)
Chr_LLp4:
RLCA
DJNZ Chr_LLp4
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 5th row
LD A,(HL)
Chr_LLp5:
RLCA
DJNZ Chr_LLp5
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 6th row
LD A,(HL)
Chr_LLp6:
RLCA
DJNZ Chr_LLp6
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 7th row
LD A,(HL)
Chr_LLp7:
RLCA
DJNZ Chr_LLp7
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 8th row
LD A,(HL)
Chr_LLp8:
RLCA
DJNZ Chr_LLp8
LD (HL),A
LD B,C
POP BC
RET
; --------------------------------
; Move char to right, 8 bit
; --------------------------------
; In : B = Nr of bits to shift
; Out: -
; Usd: A, B, HL
; --------------------------------
Chr_Rgt8:
PUSH BC
LD HL,Chr_Buf ; Rotate char right 8 bit
LD C,B ; 1st row
LD A,(HL)
Chr_RLp1:
RRCA
DJNZ Chr_RLp1
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 2nd row
LD A,(HL)
Chr_RLp2:
RRCA
DJNZ Chr_RLp2
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 3rd row
LD A,(HL)
Chr_RLp3:
RRCA
DJNZ Chr_RLp3
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 4th row
LD A,(HL)
Chr_RLp4:
RRCA
DJNZ Chr_RLp4
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 5th row
LD A,(HL)
Chr_RLp5:
RRCA
DJNZ Chr_RLp5
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 6th row
LD A ,(HL )
Chr_RLp6:
RRCA
DJNZ Chr_RLp6
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 7th row
LD A,(HL)
Chr_RLp7:
RRCA
DJNZ Chr_RLp7
LD (HL),A
LD B,C
INC HL
INC HL
LD C,B ; 8th row
LD A,(HL)
Chr_RLp8:
RRCA
DJNZ Chr_RLp8
LD (HL),A
LD B,C
POP BC
RET
; --------------------------------
; Move char to right 16 bit
; --------------------------------
; In : B = Nr of bits to shift
; Out:
; Usd: A, B, HL
; --------------------------------
Chr_Rgt16:
LD HL,(Chr_Buf); Rotate char right 16 bit
LD A,B ; 1st row
Chr_R2Lp1:
SRL L
RR H ; Insert carry
DJNZ Chr_R2Lp1
LD B,A
LD (Chr_Buf),HL
LD HL,(Chr_Buf+2); 2nd row
LD A,B
Chr_R2Lp2:
SRL L
RR H ; Insert carry
DJNZ Chr_R2Lp2
LD B,A
LD (Chr_Buf+2),HL
LD HL,(Chr_Buf+4); 3rd row
LD A,B
Chr_R2Lp3:
SRL L
RR H ; Insert carry
DJNZ Chr_R2Lp3
LD B,A
LD (Chr_Buf+4),HL
LD HL,(Chr_Buf+6); 4th row
LD A,B
Chr_R2Lp4:
SRL L
RR H ; Insert carry
DJNZ Chr_R2Lp4
LD B,A
LD (Chr_Buf+6),HL
LD HL,(Chr_Buf+8); 5th row
LD A,B
Chr_R2Lp5:
SRL L
RR H ; Insert carry
DJNZ Chr_R2Lp5
LD B,A
LD (Chr_Buf+8),HL
LD HL,(Chr_Buf+10); 6th row
LD A,B
Chr_R2Lp6:
SRL L
RR H ; Insert carry
DJNZ Chr_R2Lp6
LD B,A
LD (Chr_Buf+10),HL
LD HL,(Chr_Buf+12); 7th row
LD A,B
Chr_R2Lp7:
SRL L
RR H ; Insert carry
DJNZ Chr_R2Lp7
LD B,A
LD (Chr_Buf+12),HL
LD HL,(Chr_Buf+14); 8th row
LD A,B
Chr_R2Lp8:
SRL L
RR H ;Insert carry
DJNZ Chr_R2Lp8
LD B,A
LD (Chr_Buf+14),HL
RET
; --------------------------------
; Print 8 bit wide char on screen
; --------------------------------
; In : DE = screen adr.
; Out: -
; Usd: A, HL, DE, B
; --------------------------------
Print8:
LD HL,Chr_Buf
PUSH DE ; save scr ad.
EX DE,HL
LD B,8 ; 8 lines
Prt8_L:
LD A,(DE); set 1 byte
XOR (HL)
LD (HL),A
INC DE ; skip 1 byte
INC DE ; next byte
INC H ; calc. next line
LD A,H
AND 7
JP NZ,Prt8_C
LD A,L
ADD A,32
LD L,A
JR C,Prt8_C
LD A,H
SUB 8
LD H,A
Prt8_C:
DJNZ Prt8_L ; next round
POP DE ; restore scr ad.
RET
--------------------------------
; Print 16 bit wide char on screen
; --------------------------------
; In : DE = screen adr.
; Out: -
; Usd: A, HL, DE, B
; --------------------------------
Print16:
LD HL,Chr_Buf
PUSH DE ; save scr ad.
EX DE,HL
LD B,8 ; 8 lines
Prt16_L:
LD A,(DE); set 1 byte
XOR (HL)
LD (HL),A
INC HL ; next scr pos
INC DE ; next byte
LD A,(DE); set 1 byte
XOR (HL)
LD (HL),A
DEC HL ; prev scr pos
INC DE ; next byte
INC H ; calc. next line
LD A,H
AND 7
JP NZ,Prt16_C
LD A,L
ADD A,32
LD L,A
JR C,Prt16_C
LD A,H
SUB 8
LD H,A
Prt16_C:
DJNZ Prt16_L ; next round
POP DE ; restore scr ad.
RET
; --------------------------------
; Variables
; --------------------------------
Chr_Buf:
DEFS 16
scr_ad:
DEFW 0
pix_pos:
DEFB 0
test_text:
DEFM "This is a test for proportional print!"
DEFB 0,0
; --------------------------------
end asm
|
|
|
Fast Integer Square Roots |
Posted by: britlion - 05-26-2010, 10:12 PM - Forum: How-To & Tutorials
- Replies (3)
|
 |
A few of you have wondered why I've been obsessing over speeding up math functions, cos the compiler is for games! :-)
Well, here's a concrete example of Fast square roots in action. Part of the football algorithm is "Who do I move, and where?" on the field. I'm hoping for better graphics, but this was a mock up to look at the math of that problem. If a player is moving with the ball, who is nearest to their path to intercept them?
With players all over the place, you have to work out distances to vectors. I finally got this working correctly (it sometimes broke, the last time I looked at this - and it turned out I was crossing the 16 bit number barrier. With a newer, longer sqrt function I can go back and make the algorithm work) and here it is in two versions - one using the ROM sqr() function, and the other using isqrt.bas from http://www.boriel.com/wiki/en/index.php/...:ISqrt.bas - this is a concrete example of why the slow ROM routines can become a problem for certain aspects of certain games. The speed difference is startling. The ONLY difference in the source code is changing the square root used from ROM to library. A matter of a couple of characters and an include.
It picks a point for a ball, and draws the pass line to another player. Then every other player has a line drawn to the nearest point on that line, or the nearest end if that IS the nearest point on the line. But look at the speed difference!
Note: press ENTER for a new screen.
ROM - http://sites.google.com/site/britlion/Passing-sqr.tzx
isqrt - http://sites.google.com/site/britlion/Pa...sqrtLF.tzx
|
|
|
As BorIDE progresses... |
Posted by: LCD - 05-25-2010, 11:53 PM - Forum: ZX Basic Compiler
- Replies (143)
|
 |
Hallo my friends...
Currently the BorIDE is progressing very good. But Multitab coding is not working yet. I just want to ask if I added ALL available keywords, or are there some missing? Or are some not working?
Commands:
"And As Asm At Bold Beep Border Bright ByRef ByVal Cast Circle Cls Code Const Continue Dim Do Draw Else Elseif End Exit Fastcall Flash For Function Go Gosub Goto If Ink Inverse Italic Let Loop Malloc Multikeys Next Not Or Out Over Paper Pause Pi Plot Poke Print Randomize Realloc Return Stdcall Sub Then To Until Wend While"
Okay, I know! Pi is a constant and not a command.
Functions:
"Abs Acs Asn Atn Chr Chr$ Cos Exp Getkeyscancodes Hex Hex16 In Inkey Inkey$ Input Int Len Ln Mod Peek Point Rnd Sgn Shl Shr Sin Sqr Str Str$ Tan Val"
Assembler (I think, this is complete):
"adc add and bit call ccf cp cpd cpdr cpi cpir cpl daa dec di ei ex exx im in inc ind indr ini inir jp jr ld ldd lddr ldi ldir neg nop or outd outi pop push res ret reti retn rl rlc rlca rld rr rrc rrca rrcb rrcc rrcd rrce rrch rrcl rrd rst sbc scf set sla sra srl xor org defb defw defs defm equ"
Compiler:
"#Include Once"
Types:
"Byte Float Integer Long String Ubyte Uinteger Ulong"
Comments:
"Rem ' "
The latest version recognises now two-word commands like "Continue Do" and allow code folding. There are also different syntax coloring styles for commands, functions, comments and so. Unfortunally SUB clashes because it is available in ASM and in BASIC. Maybe changing the name from SUB to PROC will help, but then it goes away from FreeBasic names...
|
|
|
typo in scroll.bas |
Posted by: programandala.net - 05-23-2010, 10:16 AM - Forum: Bug Reports
- Replies (1)
|
 |
In library/scroll.bas, the name of the last
Code: sub fastcall ScrollLeft
should be
Code: sub fastcall ScrollUp
(I'm using 1.2.6, but just realized "zxb.py --version" reports 1.2.5-r1513. Maybe I confused the files?)
|
|
|
Suggestion about the forum |
Posted by: programandala.net - 05-23-2010, 09:48 AM - Forum: ZX Basic Compiler
- No Replies
|
 |
Now we have sub-forums for Help&Support and Documentation. That makes things tidier, especially with a growing forum.
I think this original top-level forum I'm posting into creates a kind of ambiguity, it's not clear what its purpose is any more.
I suggest to use it only for announcing new releases, or general announcements of the developer. Maybe it could be a read-only sub-forum for the users? The rest of the current messages would be moved into the proprer sub-forums.
More: This top-level forum itself could be moved into a new "Release announcements" or "Developer announcements" sub-forum, so the sub-forums list would be plain clear: no doubt where to post.
Just for your consideration.
|
|
|
A skeleton for the docs; contents hierarchy |
Posted by: programandala.net - 05-23-2010, 09:23 AM - Forum: Documentation
- Replies (1)
|
 |
I suggest to use the FreeBASIC docs as a guide, especially the FreeBASIC Table of Contents. What do you think?
By the way, I see a problem about FreeBASIC wiki: it lacks page hierarchy, it doesn't show a breadcrumb on the top, what is very important to see where we are in the page tree. Many wikis lack that feature. Some of them use the raw page name (e.g. "main.reference.functions" would be a deeper level than "main.reference"); others use page metadata to configure the hierarchy (what is more flexible because page names can change without changing the structure).
Another possible model is the PHP documentation (see an example of PHP doc page): description, parameters, return values, examples, see also, user contributions...
|
|
|
What don't we know about? |
Posted by: britlion - 05-22-2010, 10:58 PM - Forum: Documentation
- Replies (3)
|
 |
Boriel,
I am willing to help with the wiki version of documentation. Actually, I think I've probably put edits into half of it *chuckle*; including starting a "library" section and listing things like Fsin, Fsqrt and iSqrt. I think that it's possible to work out the Sinclair Basic compatible statements, but anything not compatible needs to be documented more fully. So let's start with that.
1> Are there any words that are NOT already in the reserved word list - <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Identifier#Reserved_Identifiers">http://www.boriel.com/wiki/en/index.php ... dentifiers</a><!-- m --> that we should know about?
2> Are there any extensions to the language, such as with PEEK and OVER that we don't have documented there?
|
|
|
DO WHILE and DO UNTIL |
Posted by: programandala.net - 05-22-2010, 02:31 PM - Forum: Wishlist
- Replies (5)
|
 |
Here you are my first two cents for the wishing well:
Now the DO-LOOP syntax is:
Quote:Do
[ statement block ]
Loop [ { Until | While } condition ]
I miss the following variant, allowed in FreeBASIC, Beta Basic and others:
Quote:Do [ { Until | While } condition ]
[ statement block ]
Loop
I think it's nice and clear to use just one loop structure and simply move the conditions. In fact the (less elegant, in my opinion) WHILE-WHILE END structure would be redundant (though it exists in FreeBASIC too).
|
|
|
Small snippet to make the AY scream a bit |
Posted by: na_th_an - 05-19-2010, 02:27 PM - Forum: How-To & Tutorials
- Replies (19)
|
 |
I ported some old code I developed with the aid of a couple of snippets published in Microhobby and some documentation for the AY chip to ZX Basic. The original was plain interpreted Sinclair BASIC. It may be useful to create simple sound effects, but nothing very fancy. Porting WYZ's replayer would be a better idea, but I have no time at the moment.
Try this:
Code: Dim sonidos (4, 13) As Byte => {_
{100,50,0,0,0,0,4,216,31,0,0,10,10,0}, _
{250,250,0,0,0,0,15,248,31,0,0,10,10,0}, _
{10,10,0,0,0,0,29,216,31,0,0,4,4,0}, _
{10,100,0,0,0,0,15,248,31,0,0,50,50,0}, _
{15,1,0,0,0,0,15,248,31,0,0,50,50,0} _
}
Dim n As Byte
Cls
For n = 0 To 4 ' We'll play 4 sounds
Print "SFX #"; n ' Print which one
ayPlaySound (n) ' Play sound # i
Pause 100 ' Wait for 2 secs.
Next n
Sub ayPlaySound (sonido As Byte)
' This SUB plays the sound passed as parameter
' Sounds are taken from table "sonidos", which
' must be defined globally.
Dim i As Byte
For i = 0 To 13
Out 65533, i ' Select which AY register
Out 49149, sonidos (sonido, i) ' Write a value in it
Next i
End Sub
The values in the array are pretty straightforward. The first 14 AY registers are written by the routine, just look at this table and you may create your own wacky sounds.
Code: AY REGISTERS
00 Channel A fine pitch 8-bit (0-255)
01 Channel A course pitch 4-bit (0-15)
02 Channel B fine pitch 8-bit (0-255)
03 Channel B course pitch 4-bit (0-15)
04 Channel C fine pitch 8-bit (0-255)
05 Channel C course pitch 4-bit (0-15)
06 Noise pitch 5-bit (0-31)
07 Mixer 8-bit (see below)
08 Channel A volume 4-bit (0-15, see below)
09 Channel B volume 4-bit (0-15, see below)
10 Channel C volume 4-bit (0-15, see below)
11 Envelope fine duration 8-bit (0-255)
12 Envelope course duration 8-bit (0-255)
13 Envelope shape 4-bit (0-15)
14 I/O port A 8-bit (0-255)
15 I/O port B 8-bit (0-255)
Bit:
7 6 5 4 3 2 1 0
_ _
I/O I/O Noise Noise Noise Tone Tone Tone
B A C B A C B A
|
|
|
|