Page 1 of 1

[Fixed] WEEKDAY in MENU is wrong when starting using x16emu -rtc

Posted: Sat May 13, 2023 5:32 pm
by mobluse
I use a recent ROM (GIT FF7F09C1) with R42 of the emulator on Raspberry Pi 4 (x16emu_linux-aarch64-r42).
I started the emulator using:
./x16emu -rom ../rom.bin -rtc -echo
I use the command MENU and navigate to TIME AND DATE and then everything is right except WEEKDAY which is Monday even though it is Saturday.
2023-05-13-193356_640x480_scrot.png
2023-05-13-193356_640x480_scrot.png (9.3 KiB) Viewed 5717 times
This is a separate issue:
I saved the settings from MENU (I only changed KEYMAP "EN-GB") and then did LOAD AUTOBOOT.X16 and LIST. It contains POKE for the same address twice with different values and that I don't understand the point of since the latter overwrites the first:

Code: Select all

0 COLOR$01,$06
1 SCREEN$00
2 POKE$9F29,$21
3 POKE$9F2A,$80
4 POKE$9F2B,$80
5 POKE$9F2C,$00
6 POKE$9F25,$02
7 POKE$9F29,$00
8 POKE$9F2A,$A0
9 POKE$9F2B,$00
10 POKE$9F2C,$F0
11 POKE$9F25,$00
12 KEYMAP"EN-GB"::::
13 NEW
This is perhaps a bug.

Re: WEEKDAY in MENU is wrong when starting using x16emu -rtc

Posted: Sat May 13, 2023 7:16 pm
by DragWx
I can't comment on the RTC, but I can comment on this:
mobluse wrote: Sat May 13, 2023 5:32 pm This is a separate issue:
I saved the settings from MENU (I only changed KEYMAP "EN-GB") and then did LOAD AUTOBOOT.X16 and LIST. It contains POKE for the same address twice with different values and that I don't understand the point of since the latter overwrites the first:

Code: Select all

0 COLOR$01,$06
1 SCREEN$00
2 POKE$9F29,$21
3 POKE$9F2A,$80
4 POKE$9F2B,$80
5 POKE$9F2C,$00
6 POKE$9F25,$02
7 POKE$9F29,$00
8 POKE$9F2A,$A0
9 POKE$9F2B,$00
10 POKE$9F2C,$F0
11 POKE$9F25,$00
12 KEYMAP"EN-GB"::::
13 NEW
This is perhaps a bug.
Addresses $9F29..$9F2C on the VERA are special because they're kinda like "bankswitched" registers: you use bits 1..5 of $9F25 (a.k.a. "DCSEL") to select which "page" of 4 registers show up at those addresses. (For reference, you also use bit 0 of $9F25 (a.k.a. "ADDRSEL") to select which of the two address registers you're modifying with $9F20..$9F22.)

The code above first assumes DCSEL is set to 0, so $9F29..$9F2C refers to video control, h-scale, v-scale, and border color. It sets those settings, then it sets DCSEL to 1 by writing $02 to $9F25, so now $9F29..$9F2C refers to h-start, h-stop, v-start, and v-stop. After setting those settings, it then sets DCSEL back to 0, sets the keyboard mapping, and starts a new BASIC program.

Re: WEEKDAY in MENU is wrong when starting using x16emu -rtc

Posted: Sat May 13, 2023 10:23 pm
by TomXP411
Yup.
$9f20-$9f22 are the address vectors for VERA. 20 and 21 are the lower 16 bits, and the low bit of 22 is bit 17. This allows for 128KB of RAM.

The next 6 bits of $9F22 are "DCSEL", which selects alternate modes for $9F29-9F2C. So when you see a write to $9f25, that is switching the context of those four registers.

It's all documented in the VERA PRG, here:

https://github.com/X16Community/x16-doc ... ference.md

Re: WEEKDAY in MENU is wrong when starting using x16emu -rtc

Posted: Sat May 13, 2023 10:26 pm
by TomXP411
And yes - the day of the week is incorrect in the MENU program on the emulator. I'm not sure if the RTC on the X16 dev board actually tracks the day of the week; I'll ask someone that has hardware about that.

Re: WEEKDAY in MENU is wrong when starting using x16emu -rtc

Posted: Sun May 14, 2023 11:02 am
by mobluse
It says on https://github.com/X16Community/x16-doc ... time-clock that the RTC is Microchip MCP7940N and on https://www.microchip.com/en-us/product/MCP7940N it says it supports "Day of Week".

I didn't know VERA was controlled by ordinary POKE, I believed it only used VPOKE, because so far I only used VPOKE to control VERA: e.g. in my program DECPS Player that uses PSG.

Re: WEEKDAY in MENU is wrong when starting using x16emu -rtc

Posted: Sun May 14, 2023 4:13 pm
by DragWx
mobluse wrote: Sun May 14, 2023 11:02 am I didn't know VERA was controlled by ordinary POKE, I believed it only used VPOKE, because so far I only used VPOKE to control VERA: e.g. in my program DECPS Player that uses PSG.
VPOKE is how you access the VERA's internal VRAM, which is where all of the tiles, tilemaps, bitmaps, sprites, palette, and the memory-mapped registers for the PSG are. The VERA also has several control registers (such as scrolling, base addresses for tiles, video mode, and everything related to the PCM channel) that aren't part of its internal VRAM, which you'd need to use POKE for (if there aren't already BASIC commands for those settings, that is).

Re: WEEKDAY in MENU is wrong when starting using x16emu -rtc

Posted: Mon May 15, 2023 6:40 am
by TomXP411
mobluse wrote: Sun May 14, 2023 11:02 am It says on https://github.com/X16Community/x16-doc ... time-clock that the RTC is Microchip MCP7940N and on https://www.microchip.com/en-us/product/MCP7940N it says it supports "Day of Week".

I didn't know VERA was controlled by ordinary POKE, I believed it only used VPOKE, because so far I only used VPOKE to control VERA: e.g. in my program DECPS Player that uses PSG.
VPOKE is just a special case of the POKE command.

The POKE command writes an address + data to the system bus.

VPOKE actually does 4 separate POKEs, in order: it writes the 3 bytes of the VERA address vector, then writes the VERA data value.

You can actually do the same thing VPOKE does by writing directly to $9F20-$9F22.
$9F20-$9F21 is the base address, low byte first, and $9f22 is the bank number. And as an added bonus, you can write an offset value to the high nibble and actually write repeated values to VRAM using the regular poke command.

So consider this:
100 POKE $9F20,$00
110 POKE $9F21,$B0
120 POKE $9F22,$01
130 POKE $9F23,$D3

This is the same thing as writing
100 VPOKE $1, $9F20, $D3

While that doesn't seem particularly useful, you can do stuff like this:

10 VPOKE $11,$B000,0
20 POKE $9F23,$01
30 FOR I=2 TO 128*59
40 POKE $9F23,$0
50 POKE $9F23,$01
60 NEXT

Since the auto-increment registers is actually the top nibble of the same address as the bank register, you can use bank $11 to cause the system to always advance the read/write address when the data port is accessed. So repeating $9F23 over and over again will fill the screen with data.

Re: WEEKDAY in MENU is wrong when starting using x16emu -rtc

Posted: Wed May 17, 2023 3:59 pm
by TomXP411
This is fixed in R43