How To

questions about POKEW and POKEL

0

GAMELEGEND 2020-04-26 23:09

1st question
What is the W in POKEW stand for

2nd question
When would you use POKEW instead of POKEL do you do this when you dont have that much memory to store and or change or is there some other question


was8bit 2020-04-27 04:51

Plain PEEK POKE is one byte, ...W is 2bytes ...L is 4 bytes

I just use COPY so i can do 16 at a time, great for copying pasting character data around...


was8bit 2020-04-27 04:53 (Edited)

I use PEEK so code can respond to when a voice is finished making sounds...

Audio Registers

There are registers for 4 voices:

$FF40 - Voice 0
$FF4C - Voice 1
$FF58 - Voice 2
$FF64 - Voice 3
Each voice occupies 12 bytes:

- Frequency low-byte
- Frequency high-byte
- Status:
Bit Purpose
0-3 Volume
4 Mix to left
5 Mix to right
6 Init
7 Gate
- Peak meter (read only)

IF PEEK($FF43)=0 THEN
... code....
END IF

... code responds when voice #0 goes quiet...


was8bit 2020-04-27 04:55

IF PEEK($FF43)>0 THEN
... code....
END IF

This code responds when voice #0 is sounding... great for sound repsonsive visual effects...


was8bit 2020-04-27 04:59

Here i use PEEK to respond to frequency and volumn of each sound :)

https://lowresnx.inutilis.com/topic.php?id=186


GAMELEGEND 2020-04-27 05:01

So this code
IF PEEK($FF43)=0 THEN
... code....
END IF

So is this when there is no sound coming from voice 0 or when voice 0 has stopped


GAMELEGEND 2020-04-27 05:02

Oh i have seen that program it is pretty cool i just never looked at the code


GAMELEGEND 2020-04-27 05:05

So is this the part that checks to see if the music is going and checks the how loud it is

FOR I=0 TO 3
IF P(I)>0 THEN
ADDR=$FF40+(12*I)
FL(I)=PEEK(ADDR)
FH(I)=PEEK(ADDR+1)
FR(I)=((FH(I)*256)+FL(I)-261)/300
R=8+FR(I)*FX(I)
SPR=P(I)\FACT(I)
IF P(I)>0 AND SPR=0 THEN SPR=1
IF SPR>5 THEN SPR=5
SPRCHAR=32+(2*SPR)
FOR II=(I*10+1) TO (I*10+9)
A=RND*PI*2
SPRITE II,X(I)+R*COS(A),Y(I)+R*SIN(A),SPRCHAR
NEXT II
ELSE
FOR II=I*10+1 TO I*10+9
SPRITE II,200,200,
NEXT II
END IF
NEXT I


was8bit 2020-04-27 05:05

HELP shows that $FF40 is the start of data for voice#0, and lists its bytes in,order..

PEEK($FF40) and PEEK($FF41) combined is the note frequency
PEEK($FF42) is a combination of settings, tricky to parse out though
PEEK($FF43) is the current volume of the note being played on voice#0

... i have a program for this.. give me a minute to find it :)


was8bit 2020-04-27 05:07

The code you copied,,,

FL(I)=PEEK(ADDR)
FH(I)=PEEK(ADDR+1)
FR(I)=((FH(I)*256)+FL(I)-261)/300

Actually gets the FREQUENCY, calculates it, and adjusts it for output to the visual effects, in real time...


GAMELEGEND 2020-04-27 05:08

Oops i also meant to type checks the frequency but i kind of forgot


was8bit 2020-04-27 05:09 (Edited)

Here is one of them... i will look for the others....

This one monitors VOLUME

https://lowresnx.inutilis.com/topic.php?id=831


GAMELEGEND 2020-04-27 05:10 (Edited)

So if i wanted to create one of those rhythm games i would be using PEEK and POKE and a subprogram that calculates the frequency right
But is there a way for it to know what kind of note was played mi sure there is a way right

Oh i did not realize how late it was


was8bit 2020-04-27 05:12

Oh, that one also shows frequency in the middle...


was8bit 2020-04-27 05:14

Take a really good look at the code for "SOUND MONITORING"... it should help :)


GAMELEGEND 2020-04-27 05:14 (Edited)

Ok

In about 1 or 2 days i will upload that program to this HOW TO with comments of what i think a line of code or subprogram etc does


was8bit 2020-04-27 06:51

K :)


was8bit 2020-04-27 11:21

You helped inspire a new creation :)

https://lowresnx.inutilis.com/topic.php?id=1163


GAMELEGEND 2020-04-27 19:49

Alright here it is


GAMELEGEND 2020-04-28 01:09 (Edited)

When you see this in the comments
'IM GUESSING THIS IS HERE SO WHEN THE PEAK = 0 THE MUSIC STOPS BECAUSE
'BECAUSE IS MAKES FREQUENCY = 0

Just ignore it what i want to really type is

It checks to see if the peak = 0 because if the peak = 0 the frequency should also = 0


was8bit 2020-04-28 01:35 (Edited)

For "WHAT IS THE *256+PEEK FOR"

Think of it in our number system, and lets say a computer memory could only hold 3 digits, so if you had a big number like $150,500 for the price of a house, you would store in mem1=150 and in mem2=500... but the total=M1*1000+M2 or 150*1000+500 or 150,500

In real computer memory, the biggest# is 255, or 0-255, so any number bigger would require taking the big number portion and multiply it by 256 and add the smaller number portion...


was8bit 2020-04-28 01:41 (Edited)

You are correct, NX "computer" keeps the frequency # even when the volume reaches 0... i decided thwt logically at volume 0 there is no longer any frequency so i use code manually change the frequency value to 0, even though NX doesn't care, volume 0 of any fruequency is still silent...


GAMELEGEND 2020-04-28 02:04

And what is the +0 at the end for
FREQUENCY0=PEEK(VOICEMEM(0)+1)*256+PEEK(VOICEMEM(0)+0)


was8bit 2020-04-28 03:23

From HELP...

EACH VOICE OCCUPIES 12 BYTES:
'- FREQUENCY LOW-BYTE
'- FREQUENCY HIGH-BYTE
'- STATUS:
'BIT PURPOSE
'0-3 VOLUME
'4 MIX TO LEFT
'5 MIX TO RIGHT
'6 INIT
'7 GATE
'- PEAK METER (READ ONLY)

So...
BIT +0 = low byte frequency
BIT +1 = high byte frequency
BIT +2 = status
BIT +3 = peak
...

Mathematically speaking, i could have dropped the +0 has it has no mathematical significance...

But also note this line..
PEAK0=PEEK(VOICEMEM(0)+3)

So, i thought of +0, +1, +2, +3 not only in terms of math, but also a mental reminder of which bit position i was referencing.... so these became "code names" for what they represented..

+3 reminded me of PEAK

+1 reminded me of HIGH BYTE

so +0 reminded me of LOW BYTE



was8bit 2020-04-28 03:28 (Edited)

I also could have rendered the math into their actual memory addresses..

FREQUENCY0=PEEK($FF41)*256+PEEK($FF40)
PEAK0=PEEK($FF43)

But i felt showing the math would be more useful to show what i was doing, and perhaps why i was doing it, so when others explore other NX memory map addresses they could work with those as my math shows how to do it :)


Timo 2020-04-28 17:25 (Edited)

The W is for WORD, the L for LONG. These names were sometimes used for 16 and 32 bit values.

Usually you decide depending on the maximum values you can have. For example you want to store the level number: Usually it's a value always smaller than 255, so 8 bits are enough (PEEK/POKE). A score might be much higher: If your expected max value is smaller than 32000, you can use 16 bits (W), or if it's higher you should use 32 bits (L).


GAMELEGEND 2020-04-28 17:33

Thanks timo


Log in to reply.