--
You received this message because you are subscribed to the Google Groups "MEGA65 Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-developm...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.
Cheers Paul. Not much progress at this stage, just fishing around. I also took a look at the cc65's -l listing option, pondering if I can make use of this in m65dbg at some stage to help out with this sort of debugging too.
--

--
--
--
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-developm...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.
Oh, good point, didn't notice that earlier...
I tried using the raw serial monitor commands and noticed the following:
- <dbg>d0800 (cpu-context dump)
:0000800 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00
- <dbg>m0ff80800 (28-bit address)
?SYNTAX ERROR unknown (or not implemented) command 'm'
Aah, so perhaps xemu doesn't support the 'm' version of the dump command yet, hence why my mdump wrapper returned just zeroes for everything...
--
You received this message because you are subscribed to the Google Groups "MEGA65 Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.
--
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-developm...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.
MAPH 0F00.. + MAPL 0000 + PC AA5C
-------- ------
ABSOLUTE = 0FAA5C
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.
Fair enough, will read the docs, promise :)Also, LGB, one thing I noticed while using the serial monitor hooked up to the hardware was that when I did a 'd' command, the result would return with the address given in absolute form:
As for xemu, it only displays the 16-bit address you requested.
<dbg>de1a7
:777E1A7 A5 D0 05 D1 F0 FA 20 20 ED 20 77 E1 C9 0D D0 E4
<dbg>d aa5c
:000AA5C 38 60 20 52 AA 8D 10 D6 60 20 5E AA B3 10 00 C9Any chance xemu could also return the absolute address too? Just to make it easier for noobs like me ;)
I promise I'm not using this as an excuse not to read the docs, I will read the docs, just not tonight, tired :D
<dbg>mdump ff80800 100 :FF80800 4D 36 35 55 43 4F 4E 46 49 47 55 52 45 20 4D 45 | M65UCONFIGURE ME :FF80810 47 41 36 35 00 00 00 00 00 00 00 00 00 00 00 00 | GA65............ :FF80820 00 00 00 00 A0 1B 0D 08 00 08 CC 23 01 08 0B 08 | ............. :FF80830 0A 00 9E 32 30 36 31 00 00 00 4C 64 0D 50 52 4F | ...2061...Ld.PRO :FF80840 50 2E 4D 36 35 55 2E 4E 41 4D 45 3D 43 4F 4E 46 | P.M65U.NAME=CONF


Ok, just as an experiment, I fiddled with the max-size of data that xemu loads in from the COLOURRAM.BIN file, via the line:
xemu_load_file(p, colour_ram, 0x8000, 0x8000, "Colour RAM content cannot be loaded");

00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000800 4d 36 35 55 43 4f 4e 46 49 47 55 52 45 20 4d 45 |M65UCONFIGURE ME| 00000810 47 41 36 35 00 00 00 00 00 00 00 00 00 00 00 00 |GA65............| 00000820 00 00 00 00 a0 1b 0d 08 00 08 cc 23 01 08 0b 08 |...........#....|
erasescreen:
; bank in 2nd KB of colour RAM
;
lda #$01
tsb $D030To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "MEGA65 Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-developm...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "MEGA65 Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-developm...@googlegroups.com.





dd if=mega65.img bs=1 count=512 2> /dev/null | hexdump -C -v | less
This seems to be the part of interest with the partition info for the 1st partition:
000001b0 00 00 00 00 00 00 00 00 59 88 07 d9 00 00 00 00 |........Y.......| 000001c0 01 20 0c 03 d0 ff 00 08 00 00 00 a0 0f 00 00 00 |. ..............| 000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
Ok, time to interpret what that all means:
Aah right, so if I do a dd of this 1048576 offset, I can see the boot-sector (VBR) of this 1st partition:
dd if=mega65.img bs=1 count=512 skip=1048576 2> /dev/null | hexdump -C -v | less 00000000 eb 58 90 6d 6b 66 73 2e 66 61 74 00 02 08 38 02 |.X.mkfs.fat...8.| 00000010 02 00 00 00 00 f8 00 00 10 00 04 00 81 00 00 00 |................| 00000020 00 a0 0f 00 e6 03 00 00 00 00 00 00 02 00 00 00 |................| 00000030 01 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000040 80 01 29 43 f0 a3 56 4c 4f 55 44 20 20 20 20 20 |..)C..VLOUD | 00000050 20 20 46 41 54 33 32 20 20 20 0e 1f be 77 7c ac | FAT32 ...w|.| 00000060 22 c0 74 0b 56 b4 0e bb 07 00 cd 10 5e eb f0 32 |".t.V.......^..2| 00000070 e4 cd 16 cd 19 eb fe 54 68 69 73 20 69 73 20 6e |.......This is n| 00000080 6f 74 20 61 20 62 6f 6f 74 61 62 6c 65 20 64 69 |ot a bootable di| 00000090 73 6b 2e 20 20 50 6c 65 61 73 65 20 69 6e 73 65 |sk. Please inse| 000000a0 72 74 20 61 20 62 6f 6f 74 61 62 6c 65 20 66 6c |rt a bootable fl| 000000b0 6f 70 70 79 20 61 6e 64 0d 0a 70 72 65 73 73 20 |oppy and..press | 000000c0 61 6e 79 20 6b 65 79 20 74 6f 20 74 72 79 20 61 |any key to try a| 000000d0 67 61 69 6e 20 2e 2e 2e 20 0d 0a 00 00 00 00 00 |gain ... .......| 000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
; Partitions start at offsets $1BE, $1CE, $1DE, $1EE
; so consider each in turn. Opening the partition causes other sectors to
; be read, so we must re-read the MBR between each
; get pointer to second half of sector buffer so that we can access the
; partition entries as we see fit.
;
lda #<[sd_sectorbuffer+$1BE]
sta dos_scratch_vector
lda #>[sd_sectorbuffer+$1BE]
sta dos_scratch_vector+1
I then see it prepare to read the boot-sector of the first partition, by preparing sd_address_byte0-4 to equate to the sector to read:
#4: DWORD sd_address_byte0: 00000800
...and then calling sd_readsector:
...after this, there is a call to sd_map_sectorbuffer: which I think will drop the sd-sector's contents into sd_sectorbuffer (0xDE00 - 0xDFFF) region of memory.
When it was called previouslky for reading of the MBR, the contents of sd_sectorbuffer were correct.
But after trying to read the 1st sector of the 1st partition, all I get is zeros, that's not right...
:000DE00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE90 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DEA0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DEB0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DEC0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DED0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DEE0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DEF0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF90 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFA0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFB0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFC0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFD0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFE0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFF0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
I tried GO64, and load up that default MEGA65.D81 disk image, but the LOAD "$",8 for it just returns:
I'll save that debugging journey of the .D81 file for another time.
The underlying problem is that kickstart now recognises SDHC cards that use offsets in sectors, not in bytes.Kickstart thought the card was an SDHC one, not a regular SD one. Xemu needs to handle this, and seek accordingly depending on the card mode.Paul.
--
You received this message because you are subscribed to the Google Groups "MEGA65 Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.


To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-developm...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "MEGA65 Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-developm...@googlegroups.com.
I've been pushing along trying to get the latest kickstart working with the latest xemu, so that I can press on with debugging m65-ide.
Just wanted to share some of my observations along the way. Sorry for the long-windedness.
I've used -newhack argument to my xemu call, to get the new DMA implementation Gabor implemented. That got me to the kickstart screen successfully, awesome:
...after this, there is a call to sd_map_sectorbuffer: which I think will drop the sd-sector's contents into sd_sectorbuffer (0xDE00 - 0xDFFF) region of memory.
But after trying to read the 1st sector of the 1st partition, all I get is zeros, that's not right...
:000DE00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
- So, to test my theory, I tried editing this line to become:
if (lseek(fd, image_offset*512, SEEK_SET) != image_offset*512)
Okidokey, I tinkered with xemu a bit more, to let it convince kickstart it was an SD card (and not an SDHC). As the tinker involved editing a few places here and there, I thought it'd be better to summarise it in a git commit to my forked repo:
https://github.com/gurcei/xemu/commit/de0e5725d36cfdaabd08b76b22edd74a8794ade8
Okidokey, I tinkered with xemu a bit more, to let it convince kickstart it was an SD card (and not an SDHC). As the tinker involved editing a few places here and there, I thought it'd be better to summarise it in a git commit to my forked repo:
https://github.com/gurcei/xemu/commit/de0e5725d36cfdaabd08b76b22edd74a8794ade8
I thought I'd better not do a pull request back to Gabor's repo for this, as my effort is also just a quick hack, and probably he'll eventually want to support both SD and SDHC images, and report the proper status back to kickstart accordingly.
- if (lseek(fd, image_offset*512, SEEK_SET) != image_offset*512)
I tracked down the test that decides whether this is an SD or SDHC card to within "kickstart_sdfat.a65".
There's a request to read sd_address 0x0000002, intentionally chosen to not be on 512-byte boundary. So it seems that this is something that is being used to make that decision, an SD-card can't do this, but an SDHC-card can:
; Work out if SD card or SDHC card ; SD cards only read on 512 byte aligned addresses. ; SDHC addresses by sector, so all addresses are valid ; Attempt non-aligned read lda #$02 sta sd_address_byte0 sta $d680 sdhccheckwait: jsr sdreadytest bcs issdhc bne sdhccheckwait
Then inside this jsr to sdreadytest:, I noticed that it's assessing if bits 0 and 1 of the $D680 status are on (which I saw in xemu's code equated to SD_ST_BUSY1 and SD_ST_BUSY2):
> mega65-core/src/kickstart_sdfat.a65:188 > 178: rts > 179: > 180: ; ======================== > 181: > 182: sdreadytest: ; check if SD card is ready, or if timeout has occurred > 183: ; C is set if ready. > 184: ; Z is set if timeout has occurred. > 185: ; > 186: lda $d680 > 187: and #$03 > 188: beq sdisready > 189: inc sdcounter+0 > 190: bne sr1 > 191: inc sdcounter+1 > 192: bne sr1 > 193: inc sdcounter+2 > 194: bne sr1
So the test is for a request of sd_address = 0x00000002, which is not aligned to a 512-byte boundary.
Hiya Gabor,
> First of all, thanks for your efforts and the nice work :)
No probs, I enjoyed the adventure :) And thanks for the compliment on my testing discoveries! :D I appreciate the detail you've gone to in your responses, just sadly my speed of comprehension can be a bit slow, and I tend to need to re-read things multiple times before the penny drops :) I'll try cover the bits I can respond to immediately though below.
> Surely, I also tested with new KS, and what I found, that I have issue with the hardware accelerated ASCII keyboard thinggy, so I can't even do too much, when it waited for keypress to utility etc, it simply does not work. If I remove the "empty FIFO" policy, it works, just then the keypress stuck forever, well, not so surprisingly. What I think here (but I can be wrong!!!) that M65 has some issues (as Paul mentioned too) with that too. And maybe I don't emulate the "issues", or at least not the really same ones ;-P
Yes, agreed, I've also witnessed some problems with keypresses that aren't registering properly within the kickstart menu. I think I also noticed that if I press the TAB key during kickstart, it gets upset with me, with this message:
I haven't looked into that as yet. Sometimes it takes me by surprise when I alt-tab between the app and another window (with the tab key in the alt-tab triggering this crash :)), so just thought I'd give some heads-up on this observation too.
> Don't do that. Xemu basically emulates non-SDHC card (so <2Gbyte), where addressing is BYTE based (that's the reason it's not multiplied with 512 by default, as byte addressing is used there!).
- if (lseek(fd, image_offset*512, SEEK_SET) != image_offset*512)
Hehe, yup, the *512 was a silly thing I tried initially, not knowing any better. Ah well, the silly way taught me some lessons and evolved my understanding on the matter. The improved technique I did in the fork commit avoids doing this multiplication and instead tries to convince kickstart that it is an SD-card rather than an SDHC card, hence keeps the lseek() in units of bytes.
XEMU_DEBUG_FILE=debug1.log ./build/bin/xmega65.native -loadcram ../mega65-core/bin/COLOURRAM.BIN -skipunhandledmem -newhack -8 ../mega65-ide/M65IDE.D81
With these two extra -kickuplist and -hyperdebug parameters:
XEMU_DEBUG_FILE=debug2.log ./build/bin/xmega65.native -loadcram ../mega65-core/bin/COLOURRAM.BIN -skipunhandledmem -newhack -8 ../mega65-ide/M65IDE.D81 -kickuplist ../mega65-core/kickstart.list -hyperdebug
I did a diff between the debug1.log and debug2.log files, and I saw that this sort of extra output gets added into debug2.txt (the one with the extra two parameters):
DMA: initiation of ENCHANCED MODE DMA!!!!
DMA: list address is $FFFA83A now, just written to register 0 value $3A @ PC=$A7E2
HYPERVISOR-DEBUG: A9 01 LDA #$01 PC=A7E2 SP=BEFB B=BF A=3A X=00 Y=00 Z=00 P=nvE-dIzC IO=3 OPC=A9 @ kickstart.a65:1781
DMA: enhanced option byte $0A read
DMA: enhanced option byte $00 read
DMA: end of enhanced options
DMA: READ COMMAND: $0000400[MEM 1:0] -> $0000404[MEM 1:0] (L=$07CC) CMD=0 (CHAINED)
HYPERVISOR-DEBUG: A9 01 LDA #$01 PC=A7E2 SP=BEFB B=BF A=3A X=00 Y=00 Z=00 P=nvE-dIzC IO=3 OPC=A9 @ kickstart.a65:1781
DMA: end of operation, but chained!
DMA: enhanced option byte $00 read
DMA: end of enhanced options
DMA: READ COMMAND: $0000001[MEM 1:0] -> $0000800[I/O 1:0] (L=$07D0) CMD=3 (CHAINED)
DMA: end of operation, but chained!
DMA: enhanced option byte $00 read
DMA: end of enhanced options
DMA: READ COMMAND: $0004000[MEM 1:0] -> $0004000[MEM 1:0] (L=$6000) CMD=0 (LAST)
HYPERVISOR-DEBUG: A9 01 LDA #$01 PC=A7E2 SP=BEFB B=BF A=3A X=00 Y=00 Z=00 P=nvE-dIzC IO=3 OPC=A9 @ kickstart.a65:1781
HYPERVISOR-DEBUG: A9 01 LDA #$01 PC=A7E2 SP=BEFB B=BF A=3A X=00 Y=00 Z=00 P=nvE-dIzC IO=3 OPC=A9 @ kickstart.a65:1781
HYPERVISOR-DEBUG: A9 01 LDA #$01 PC=A7E2 SP=BEFB B=BF A=3A X=00 Y=00 Z=00 P=nvE-dIzC IO=3 OPC=A9 @ kickstart.a65:1781
Ah ok, I think the penny is dropping, all three of these things need to be used in unison (XEMU_DEBUG_FILE + -kickuplist + -hyperdebug) and then you will get these extras in the debug file.
Hiya Gabor,
MONITOR
A C000 LDA #$7C LDY #$21 STA $D640 NOP RTS X GO64 SYS 49152
But sadly I didn't see anything in the serial comms output. I pushed a fairly new bitstream onto the device.
MEGA65 Serial Monitor
build px100m,ae2dadb+DIRTY,20180210.10As this technique that Paul offered for serial debug output was a trap (a topic I wasn't too familiar with), I remember bumping into trap usage in the "diskmenu.a65" tool... I had a look in the code there, because I suspected that I was missing something, and I think I'm missing this bit:
;------------------------------------------------------------------------------- initM65IO: ;------------------------------------------------------------------------------- ; Enable enhanced registers LDA #$47 ;M65 knock knock STA $D02F LDA #$53 STA $D02F RTS
Aah, ok, let me add that to my example then...
MONITOR A C000 LDA #$47 STA $D02F LDA #$53 STA $D02F NOP NOP LDA #$7C LDY #$21 STA $D640 NOP RTS X GO64 Y SYS 49152
Ah awesome, I stepped through this and the trap stuff triggered and went to this part of the code! :)
> /home/gurce/mega65/mega65-core/src/kickstart_dos.a65:204 > 194: .word trap_task_toggle_rom_writeprotect > 195: .word invalid_subfunction > 196: .word invalid_subfunction > 197: .word invalid_subfunction > 198: .word invalid_subfunction > 199: .word invalid_subfunction > 200: .word trap_serial_monitor_write > 201: .word reset_entry > 202: > 203: trap_serial_monitor_write: > 204: STY $D67C > 205: jmp return_from_trap_with_success > 206: > 207: ; ======================== > 208: > 209: trap_task_toggle_rom_writeprotect: > 210: LDA hypervisor_feature_enables > 211: EOR #$04 > 212: STA hypervisor_feature_enables > 213: jmp return_from_trap_with_success > 214:
Awesome, the trap triggered :) I tried to catch the serial debug output via minicom terminal with:
minicom -D unix#/home/gurce/mega65/xemu/uart.sock -b 2000000
But sadly no output seen... I'm suspecting that xemu doesn't support this form of hypervisor-debug serial output as yet...
So I tried it on the nexys hardware just now, and awesome, it worked!
MONITOR A C000 LDA #$47 STA $D02F LDA #$53 STA $D02F NOP NOP LDA #$7C LDY #$21 STA $D640 NOP
LDA #$7C LDY #$0A STA $D640 NOP
RTS X GO64 Y SYS 49152
unsigned char mybyte; #pragma optimize(off) void send_debug(void) { char s[20] = "Hello world!\n"; int k; // init M65 IO POKE(0xd02f,0x47); POKE(0xd02f,0x53); for (k = 0; s[k] != '\0'; k++) { mybyte = s[k]; __asm__ ( "lda #$7C" ); __asm__ ( "ldy %v", mybyte); // (unsigned char)s[k]); __asm__ ( "sta $D640" ); __asm__ ( "nop" ); } // reset it back to normal? //POKE(0xd031,0); // VIC-II IO mode //POKE(0xd02f,0); } #pragma optimize(on)
I learnt that I needed to turn optimisation off for the inline assembly to work properly.
The results were a little sub-par though. In the xemu console stderr output, I see:
Hypervisor serial output: "LLO WORLD!".
So, it's missing the first two letters of "HE".
I tried stepping through send_debug() with m65dbg, it seems like something went wrong with how the cc65 compiler accessed this string, so I'll have to get better acquainted with cc65 to figure out what made it unhappy...
Ah well, getting closer... :)
--
You received this message because you are subscribed to the Google Groups "MEGA65 Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-development+unsubscribe@googlegroups.com.
"Note: Inline assembler statements are subject to all optimizations done by the compiler. There currently is no way to protect an inline assembler statement -- alone -- from being moved or removed completely by the optimizer. If in doubt, check the generated assembler output; or, disable optimizations (for that function)."
But that's interesting, that switching optimization off does not help either.
What I would do, is trying to put only the output of a single byte into a separate function and calling that then. Or even better, code that primitive in an assembly source, assemble with ca65 and then link into your project. So cc65 will use your function that was never a C code compiled by itself, no chance that it could mess it up ;-P From just seeing the asm output of a test c file, I guess it would something like this:
.segment "CODE"
.export _myfunc
.proc _myfunc: near
.segment "CODE"
jsr pusha
ldy #$00
ldx #$00
lda (sp),y
sta _global_ch
jsr incsp1
rts
.endproc
Then you need to declare the prototype of the C function in C at least, ie:
void __near__ myfunc (unsigned char);
or such. Or even better you can try the __fastcall__ stuff, which uses to pass the first arg of the function in a CPU register, not even using stack then.
Hypervisor serial output: "LLO WORLD!".
FROM: char s[20] = "Hello world!\n"; TO: char s[20] = "hello world!\n";
Hypervisor serial output: "HELLO WORLD!".
I had a look at my issue of the truncated serial output previously:Hypervisor serial output: "LLO WORLD!".
Then by chance, I managed to get it to work properly by tweaking the line from send_debug() as follows:FROM: char s[20] = "Hello world!\n"; TO: char s[20] = "hello world!\n";
Aah, so it seems like the capital letter 'H' screwed up the prior string for me, as now I get the proper serial output of:Hypervisor serial output: "HELLO WORLD!".
Hello,So we should do PETSCII->ASCII conversion before printing the messages out I guess?
Meanwhile, Holger (in CC) is having some trouble running Synthmark64 and some other programs under the latest Xemu. Perhaps you can help him figure out what is going wrong.
Hello,
There is a way to stop cc65 from messing up the codes, but I can't remember how. Part of the trouble is if you fix it that way, then it fixes it for all uses of strings, which might not be what you want.
If a string printed out is unambigiously PETSCII, i.e., would not be valid UTF8, then we can be fairly sure it is PETSCII, and displaying on the debug output it is therefore reasonable to show it converted to ASCII. You could have a command line argument to enable/disable this behaviour in Xemu, so that if you really want it raw, it is possible.How about this for an idea:
-hyperserialascii option is implemented in Xemu (well, I guess I should use shorter names for options ...). It tries convert any possible alphabet range (ASCII+PETSCII lower/upper case) to ASCII upper case only. Surely it's maybe not ideal, but it's not possible too much to do better without knowing that encoding actually used by the program run on M65. Other characters with >0x80 value are replaced with '?' which may left after the conversion.
--
I'll try jot down some steps to replicate:



Ok, now we can try debugging things:
PC A X Y Z B SP MAPL MAPH LAST-OP P P-FLAGS RGP uS IO
4D94 00 00 04 00 00 01E6 0000 0000 20 22 00 --E---Z-
---------------------------------------
no watches in list
---------------------------------------
$4D94 M_impl:0 48 PHA
<dbg>
Hmm, this isn't where we hoped for, but not to worry, it's because the
hardware breakpoints will stop the CPU at the instruction *after* the
breakpoint, and for a JSR instruction, that will be within the JSR
subroutine itself.
Not to worry, let's do a "down" instruction to drop down the stack a level. Now we see:
---------------------------------------
no watches in list
---------------------------------------
<<< FRAME#: 1 >>>
> m65ide.list:5975
> 5965: 0003FAr 1
> 5966: 0003FAr 1 .segment "CODE"
> 5967: 0003FAr 1
> 5968: 0003FAr 1 .proc _line_fetch: near
> 5969: 0003FAr 1
> 5970: 0003FAr 1 .segment "CODE"
> 5971: 0003FAr 1
> 5972: 0003FAr 1 ;
> 5973: 0003FAr 1 ; {
> 5974: 0003FAr 1 ;
> 5975: 0003FAr 1 20 rr rr jsr pushax
> 5976: 0003FDr 1 ;
> 5977: 0003FDr 1 ; send_debug("line-fetch(line=%d)", line_number);
> 5978: 0003FDr 1 ;
> 5979: 0003FDr 1 20 rr rr jsr decsp5
> 5980: 000400r 1 A9 rr lda #<(L00F2)
> 5981: 000402r 1 A2 rr ldx #>(L00F2)
> 5982: 000404r 1 20 rr rr jsr pushax
> 5983: 000407r 1 A0 0A ldy #$0A
> 5984: 000409r 1 20 rr rr jsr pushwysp
> 5985: 00040Cr 1 A0 04 ldy #$04
---------------------------------------
$2328 M_nnnn:2 20 94 4D JSR $4D94
<dbg>
Notice how we now see the source of the "m65ide.list" file.
I gave the cc65 compiler the "--add-source" parameter so that it
embeds each line from the c-source code into the generated assembly as a
comment.
I can then set a breakpoint further along in this code by line-number and continue to it:
break :5980
c
PC A X Y Z B SP MAPL MAPH LAST-OP P P-FLAGS RGP uS IO 2330 83 00 00 00 00 01E8 0000 0000 A9 A1 00 N-E----C --------------------------------------- no watches in list --------------------------------------- > m65ide.list:5981 > 5971: 0003FAr 1 > 5972: 0003FAr 1 ; > 5973: 0003FAr 1 ; { > 5974: 0003FAr 1 ; > 5975: 0003FAr 1 20 rr rr jsr pushax > 5976: 0003FDr 1 ; > 5977: 0003FDr 1 ; send_debug("line-fetch(line=%d)", line_number); > 5978: 0003FDr 1 ; > 5979: 0003FDr 1 20 rr rr jsr decsp5 > 5980: 000400r 1 A9 rr lda #<(L00F2) > 5981: 000402r 1 A2 rr ldx #>(L00F2) > 5982: 000404r 1 20 rr rr jsr pushax > 5983: 000407r 1 A0 0A ldy #$0A > 5984: 000409r 1 20 rr rr jsr pushwysp > 5985: 00040Cr 1 A0 04 ldy #$04 > 5986: 00040Er 1 20 rr rr jsr _send_debug > 5987: 000411r 1 ; > 5988: 000411r 1 ; t_old = get_start_time(); > 5989: 000411r 1 ; > 5990: 000411r 1 20 rr rr jsr _get_start_time > 5991: 000414r 1 A0 01 ldy #$01 --------------------------------------- $2330 M_immnn:1 A2 54 LDX #$54 <dbg>
...and there ya go, it hit the breakpoint and is waiting at the next instruction/line after this (:5981)
Anyway, that's just a little sampler of where it's at right now. It's a bit rough, but it's a start :)
well done!
On 18 April 2018 at 21:47, LGB Gábor Lénárt <lgbl...@gmail.com> wrote:
-hyperserialascii option is implemented in Xemu (well, I guess I should use shorter names for options ...). It tries convert any possible alphabet range (ASCII+PETSCII lower/upper case) to ASCII upper case only. Surely it's maybe not ideal, but it's not possible too much to do better without knowing that encoding actually used by the program run on M65. Other characters with >0x80 value are replaced with '?' which may left after the conversion.
--
You received this message because you are subscribed to the Google Groups "MEGA65 Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to c65gs-developm...@googlegroups.com.

Hi guys,
I've been pushing along trying to get the latest kickstart working with the latest xemu, so that I can press on with debugging m65-ide.
Just wanted to share some of my observations along the way. Sorry for the long-windedness.
I've used -newhack argument to my xemu call, to get the new DMA implementation Gabor implemented. That got me to the kickstart screen successfully, awesome:
But if I choose option 2, I get this:
If I choose option 1 though, looks good:
If I then press F10 in xemu (for a soft restart) and then select option 2, it then displays correctly:
I did the "DELETE EVERYTHING" command. I was applying this to a raw/fresh mega65.img file that xemu had offered to autogenerate, so I wasn't worried about losing anything.
However, upon completion, the sd-card is still un-usable. After having a look at the mega65.img file via hexdump, all bytes are still zero, so nothing was written to them.
Ah well, perhaps this could relate to the new dma implementation, so I didn't push much further in that direction.
I instead tried using Gabor's pre-prepared image from online. I'll share how that went.But when I use this image and re-run xemu, it still offers the utility menu:
- wget https://raw.githubusercontent.com/lgblgblgb/xemu/gh-pages/files/sd-card-image-for-xemu-xmega65.img.gz
- gunzip -k sd-card-image-for-xemu-xmega65.img.gz
- mv sd-card-image-for-xemu-xmega65.img "~/.local/share/xemu-lgb/mega65/mega65.img"
This surprised me somewhat, as I thought that this utility menu should only appear when the alt key is down. After looking at the .a65 source, I learnt it also appears when no disks are found on the sdcard image.
Aah, so that's why the disk-count in the kickstart bootup was showing as zero:
I mounted the mega65.img locally and confirmed it definitely had content on it, and a .D81 file. So then it became a question of why it wasn't being located.
I did some debugging around the readmbr: section of the assembly and confirmed it retrieved the MBR from sector 0 successfully, and it matches what I see in the mega65.img file via dd and hexdump:dd if=mega65.img bs=1 count=512 2> /dev/null | hexdump -C -v | less
This seems to be the part of interest with the partition info for the 1st partition:
000001b0 00 00 00 00 00 00 00 00 59 88 07 d9 00 00 00 00 |........Y.......| 000001c0 01 20 0c 03 d0 ff 00 08 00 00 00 a0 0f 00 00 00 |. ..............| 000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|Ok, time to interpret what that all means:
- 00 00 01 20 0c 03 d0 ff 00 08 00 00 00 a0 0f 00
- 0c = partition type = FAT32 with LBA (not CHS)
- Aah, since we're using LBA, the CHS fields of this partition entry can be ignored, I think...
- 00 08 00 00 = LBA of first sector in partition
= 0x00000800
= sector 2048
= 2048 x 512 = 1048576 'th byte
- 00 a0 0f 00 = Number of sectors in partition
= 0x000fa000
= 1024000 sectors
= 524288000 bytes
= 500 MBAah right, so if I do a dd of this 1048576 offset, I can see the boot-sector (VBR) of this 1st partition:
dd if=mega65.img bs=1 count=512 skip=1048576 2> /dev/null | hexdump -C -v | less 00000000 eb 58 90 6d 6b 66 73 2e 66 61 74 00 02 08 38 02 |.X.mkfs.fat...8.| 00000010 02 00 00 00 00 f8 00 00 10 00 04 00 81 00 00 00 |................| 00000020 00 a0 0f 00 e6 03 00 00 00 00 00 00 02 00 00 00 |................| 00000030 01 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000040 80 01 29 43 f0 a3 56 4c 4f 55 44 20 20 20 20 20 |..)C..VLOUD | 00000050 20 20 46 41 54 33 32 20 20 20 0e 1f be 77 7c ac | FAT32 ...w|.| 00000060 22 c0 74 0b 56 b4 0e bb 07 00 cd 10 5e eb f0 32 |".t.V.......^..2| 00000070 e4 cd 16 cd 19 eb fe 54 68 69 73 20 69 73 20 6e |.......This is n| 00000080 6f 74 20 61 20 62 6f 6f 74 61 62 6c 65 20 64 69 |ot a bootable di| 00000090 73 6b 2e 20 20 50 6c 65 61 73 65 20 69 6e 73 65 |sk. Please inse| 000000a0 72 74 20 61 20 62 6f 6f 74 61 62 6c 65 20 66 6c |rt a bootable fl| 000000b0 6f 70 70 79 20 61 6e 64 0d 0a 70 72 65 73 73 20 |oppy and..press | 000000c0 61 6e 79 20 6b 65 79 20 74 6f 20 74 72 79 20 61 |any key to try a| 000000d0 67 61 69 6e 20 2e 2e 2e 20 0d 0a 00 00 00 00 00 |gain ... .......| 000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
So the partition information in the image is legit...
- I step through the code around dos_read_partitiontable: and kickstart_dos.a65:728:
; Partitions start at offsets $1BE, $1CE, $1DE, $1EE
; so consider each in turn. Opening the partition causes other sectors to
; be read, so we must re-read the MBR between each; get pointer to second half of sector buffer so that we can access the
; partition entries as we see fit.
;lda #<[sd_sectorbuffer+$1BE]
sta dos_scratch_vector
lda #>[sd_sectorbuffer+$1BE]
sta dos_scratch_vector+1
I then see it prepare to read the boot-sector of the first partition, by preparing sd_address_byte0-4 to equate to the sector to read:
#4: DWORD sd_address_byte0: 00000800
...and then calling sd_readsector:
...after this, there is a call to sd_map_sectorbuffer: which I think will drop the sd-sector's contents into sd_sectorbuffer (0xDE00 - 0xDFFF) region of memory.
When it was called previouslky for reading of the MBR, the contents of sd_sectorbuffer were correct.
But after trying to read the 1st sector of the 1st partition, all I get is zeros, that's not right...
:000DE00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DE90 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DEA0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DEB0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DEC0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DED0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DEE0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DEF0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DF90 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFA0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFB0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFC0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFD0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFE0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
:000DFF0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
I then took a look inside xemu's "targets/mega65/sdcard.c" to learn how this sdcard reading was done.
- I saw sdcard_command() had case 0x02: for reading a block
- This called diskimage_read_block() to do this task, feeding it an offset via the sd_sector_bytes parameter (which equated to the correct 0x00000800 offset requested).
- Within diskimage_read_block() was a call to host_seek_to() which I then found a point of concern:
if (lseek(fd, image_offset, SEEK_SET) != image_offset)
- This image_offset value equated to 0x00000800 (passed in via sd_sector_bytes), which is the correct offset, but in units of sectors. The lseek() function is seeking in units of bytes.
- So, to test my theory, I tried editing this line to become:
if (lseek(fd, image_offset*512, SEEK_SET) != image_offset*512)
- I ran xemu again, and hey presto! The c65 startup screen is back! No more utility menu! :)
I tried GO64, and load up that default MEGA65.D81 disk image, but the LOAD "$",8 for it just returns:
I'll save that debugging journey of the .D81 file for another time.