Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Z80 disassembler MMB4W
Author | Message | ||||
electricat Senior Member Joined: 30/11/2020 Location: LithuaniaPosts: 161 |
Hi, I wrote yet another Z80 disassembler (in MMBASIC4W). With undocumented instructions implemented. It reads bin files (*.sna for example) and disassembles them, of course. Now I would like to test it against errors. (I tested against some *sna files and it looks OK, but for example Ms.Pacman uses not so much undocumented instructions) Of course, I could write my own asm bin, for testing, but it takes some few additional and boring hours. I'm just wondering if there are any bins already created for this purpose. If yes, could anybody point me to a source or share? Also another question. Well, I used LEFT$ and RIGHT$ for formating output, but it would be much faster just mach some keywords in ASM mnemonics for example "LD A,n" and replace "n" with value$ prepared. I looked and searched through manual, but failed to find such function. I am overlooking something or there is no such funcion? |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
Remember you can use MID$ on the left side of an argument. A$="........" MID$(A$,3,2)="XY" PRINT A$ ..XY.... Also, watch out for the Z80 restart instructions. I don't know about other systems but the Nascom used them extensively as pseudo-ops to do things RCAL (relative call - very handy for writing relocatable code) and outputting a string to the current device. That leads to characters after them being data, not commands. e.g. EF 41 42 43 00 would print ABC to the screen by default on a Nascom. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2076 |
the CPC did also. Very good OS with shadowing of both upper an lower ROMs used RSTs to do common tasks predictably. Off the top of my head I remember the kernel called RAM LAM which was a LD A,(HL) always from the shadowed RAM regardless of the state of ROM selection bits. I miss those days |
||||
electricat Senior Member Joined: 30/11/2020 Location: LithuaniaPosts: 161 |
Yes, Mick. But MID$ is like LEFT$, like RIGHT$. You still need to calculate the exact position. Search/replace strings by pattern would be so much simpler. Then I must write a dedicated function, maybe for search/replace by pattern. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
I'm not certain what you are looking for. The usual way to do a dissassembler AFAIK is to do successive searches. For example, group commands into single byte, two byte three byte etc. Take first byte from file and search 4-byte list (use INSTR()? ) if it's there then the next 3 bytes can be searched for modifiers and then values. If it's not a 4-byte then search the 3-byte commands. etc. For outputting all lines are basically identical in format. Hex address - command - modifier - value - maybe an ASCII equivalent character. The line can be done with TABs or written into a format string using MID$() then output to screen, foile or whatever. You don't usually need to calculate positions, you just have a column for each. e.g. 0041 LD HL 1000 0044 LD A (HL) 0045 INC HL 0046 LD (DE) A or something like that. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
electricat Senior Member Joined: 30/11/2020 Location: LithuaniaPosts: 161 |
Mick, You are 100% right! But I do not like unnecessary tabs! :D Take a look, what my program outputs : Basicly, the job is done in both ways, but I want formatted text like I prefer. (not the straight-forward way) And for this reason, I preformed ED, FD, DDCB mnemonics in text files (tabs, spaces) in advance, so I would only replace 'NN' , 'N' values later. Now to reach what I want I use LEFT$, RIGHT$, but with pattern serach/replace, for ecample '#NN#' replace with '46009' final program would be more elegnat and easy to read and understand to somebody. Thats all buzz about :D By the way - my rotating hobby of hobbies is reverse engineering old ZX Spectrum programs. I can happily live with the bunch of b/w disassemblers we have already, but they are boring :D |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3804 |
Quite a few disassemblers can readily output decimal, hex, ascii, etc for data, operands, etc. The more intelligent ones can figure out awkward things like jump tables. No reason why commonly recognised chunks of code can't be listed as (say) C, perhaps in comments. With lots of memory you can do lookups fast on multi-byte sequences. (Not on a typical uC MMBasic, as short of memory.) The bigger the input, the more intelligent you tend to want the tool or you drown in unhelpful stuff. Some tools can be fed not just the data to disassemble but hints/etc to influence/control the tool e.g. from earlier runs where the user has noticed things. All rather depends on personal preference and what you're trying to achieve. John |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
Would the FIELD$() function be useful here? I suspect that the most useful output is a plain text file. I've usually ended up printing them out and going over them with a pencil to add comments/notes/scribbles. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
electricat Senior Member Joined: 30/11/2020 Location: LithuaniaPosts: 161 |
@Johns Ok ok... coming back to write functions I need and useless disassembler iteration v0.3. Well.. useless assembler too :D Edited 2023-05-25 06:47 by electricat |
||||
electricat Senior Member Joined: 30/11/2020 Location: LithuaniaPosts: 161 |
Mick, thank you. I`ll take a look ayt Fields function. Today am already full of dried frogs :D |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6101 |
Does this help ' code1$ = "DJNZ,#NN#" PRINT replace$(code1$,"#NN#","8080") PRINT replace$(code1$,"#Nn#","8080",1,1) ' str to search, str to replace, str to replace with, ' s = starting char for search, c = ignore case FUNCTION replace$(string1$,string2$,string3$,s AS INTEGER, c AS INTEGER) LOCAL INTEGER n,k IF s = 0 THEN s = 1 IF c THEN ' ignore case in comparison k = INSTR(s,UCASE$(string1$),UCASE$(string2$)) ELSE k = INSTR(s,string1$,string2$) ENDIF replace$= LEFT$(string1$,k-1)+string3$+MID$(string1$,k+LEN(string2$)) END FUNCTION Edit to add "ignore case" in strings Jim Edited 2023-05-25 08:33 by TassyJim VK7JH MMedit MMBasic Help |
||||
electricat Senior Member Joined: 30/11/2020 Location: LithuaniaPosts: 161 |
@TassyJim, yes :) ! INSTR( [start-position,] stringsearched$,string-pattern$ ) is what I overlooked. And this was the answer I needed! Thank you! |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
I like INSTR(). You tend to find it quite a bit in my code, often followed by a SELECT-CASE. :) Edited 2023-05-25 16:38 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
electricat Senior Member Joined: 30/11/2020 Location: LithuaniaPosts: 161 |
I also like Jim`s online MMBasic Help :) Nice and clean HTML. |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6101 |
It is a bit out of date now. I will try and update it over the coming winter and get a few more example codes in. The version bundled with MMEdit is often more up to date. Jim VK7JH MMedit MMBasic Help |
||||
hhtg1968 Senior Member Joined: 25/05/2023 Location: GermanyPosts: 123 |
HI. Is there a z80 emulator for mmbasic? in former times (80´s) i wrote a lot of z80 assembler programs. perhabs i decide to wrote such an emulator. |
||||
electricat Senior Member Joined: 30/11/2020 Location: LithuaniaPosts: 161 |
Take a look at this >> Z80 simulator for CMM2 https://www.thebackshed.com/forum/ViewTopic.php?TID=15192&P=1 |
||||
electricat Senior Member Joined: 30/11/2020 Location: LithuaniaPosts: 161 |
I wget`d it offline for myself (to add my own notes/examples locally). I did not notice your online help at first, so I started my own and made some sort of compact CMM2 help in doc form (prepared texts for HTML). But you've already done much more. I might have something to share with you as time goes on, and if you decide it might be interesting, I would be happy to be somehow useful for the community. And yes, your MMEdit I found so much usefull in combination with CMM2 !! |
||||
Print this page |