Giter VIP home page Giter VIP logo

emulator101's Introduction

emulator101

Source code to all the tutorials on emulator101.com

emulator101's People

Contributors

kpmiller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emulator101's Issues

The Real Experience | Added Support for Original Green and Red Gels

The classic arcade Space Invaders had a B&W monitor. The colors of the aliens were applied via transparent gels on the screen. I added these to the emulation to improve the antic feel of the game.

InvadersView.m

#define RGB_ON   0xFFFFFFFFL
#define RGB_OFF   0x00000000L
#define RGB_GREEN   0x00FF0000L
#define RGB_RED     0x0000FF00L

            for (p=0; p<8; p++)
            {
                if ( 0!= (pix & (1<<p))) {
                    if ( (j > 8 && j < 76) || (j <= 8 && i > 20 && i < 108) )
                        *p1 = RGB_GREEN;
                    else if (j > 190 && j < 222)
                        *p1 = RGB_RED;
                    else
                        *p1 = RGB_ON;
                } else
                    *p1 = RGB_OFF;
                p1-=224;  //next line
            }

The display char code

Just a small comment about this page, and in particular, this:

                {    
                    //saw this in the inspected code, never saw it called    
                    printf ("print char routine called\n");    

Actually, this code is called. When the error message CPU HAS FAILED! ERROR EXIT= is displayed, the routine continues, it picks up the address on the stack, puts it in H and L with XTHL, and then displays the address in these two registers character per character. The routine BYTE0 takes the value of A and displays its two digits.

Once you have implemented this correctly, the error message contains the address where the exit occurred. This is what my emulator displays, for example:

CPU HAS FAILED! ERROR EXIT=01B6

Great document otherwise, thanks!

Some mistakes in the z80 c sourcecode

0xb0 in the disassembler has an instruction, but in the emulator function it is set to unimplemented.

There are actually a few instructions like this in this area.

gdb against invaders produces a never-ending file?

Hey - I was following the emulator101 site (and Im thankful it exists! What a wonderful getting started with emulation write up!)

I just have a question, I tried to disassemble invaders, but looks like at some point, the program is not ending, but just continues to chew up space by writing:

0aea XRA    A	z.p..  A $00 B $00 C $00 D $1f E $b0 H $3e L $01 SP 2400
0aeb OUT    #$03	z.p..  A $00 B $00 C $00 D $1f E $b0 H $3e L $01 SP 2400
0aed OUT    #$05	z.p..  A $00 B $00 C $00 D $1f E $b0 H $3e L $01 SP 2400
0aef CALL   $1982	z.p..  A $00 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
1982 STA    $20c1	z.p..  A $00 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
1985 RET	z.p..  A $00 B $00 C $00 D $1f E $b0 H $3e L $01 SP 2400
0af2 EI	z.p..  A $00 B $00 C $00 D $1f E $b0 H $3e L $01 SP 2400
0af3 CALL   $0ab1	z.p..  A $00 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0ab1 MVI    A,#$40	z.p..  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0ab3 JMP    $0ad7	z.p..  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0ad7 STA    $20c0	z.p..  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0ada LDA    $20c0	z.p..  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0add ANA    A	.....  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0ade JNZ    $0ada	.....  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0ada LDA    $20c0	.....  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0add ANA    A	.....  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0ade JNZ    $0ada	.....  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0ada LDA    $20c0	.....  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0add ANA    A	.....  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0ade JNZ    $0ada	.....  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe
0ada LDA    $20c0	.....  A $40 B $00 C $00 D $1f E $b0 H $3e L $01 SP 23fe

this repeats over and over until the file chews up all my space or ram.

I was wondering, is the disassembler supposed to get to a certain point and stop itself?

Most of the beginning stuff seems to be in line with the tutorial, but maybe I was doing something wrong?

I took your program and ran:

invaders % cc -g -O0 8080emu-first50.c -o test.out
invaders % sudo gdb test.out

I got gdb to work which was not super easy hah, I am also on a Mac, so your tutorials are great!

GNU gdb (GDB) 9.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin19.3.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test.out...
Reading symbols from /Users/futurepr0n/Downloads/invaders/test.out.dSYM/Contents/Resources/DWARF/test.out...
(gdb) run invaders
Starting program: /Users/futurepr0n/Downloads/invaders/test.out invaders
[New Thread 0xd03 of process 55472]
[New Thread 0x1603 of process 55472]
0000 NOP	.....  A $00 B $00 C $00 D $00 E $00 H $00 L $00 SP 0000
0001 NOP	.....  A $00 B $00 C $00 D $00 E $00 H $00 L $00 SP 0000
0002 NOP	.....  A $00 B $00 C $00 D $00 E $00 H $00 L $00 SP 0000
0003 JMP    $18d4	.....  A $00 B $00 C $00 D $00 E $00 H $00 L $00 SP 0000
18d4 LXI    SP,#$2400	.....  A $00 B $00 C $00 D $00 E $00 H $00 L $00 SP 2400
18d7 MVI    B,#$00	.....  A $00 B $00 C $00 D $00 E $00 H $00 L $00 SP 2400
18d9 CALL   $01e6	.....  A $00 B $00 C $00 D $00 E $00 H $00 L $00 SP 23fe
01e6 LXI    D,#$1b00	.....  A $00 B $00 C $00 D $1b E $00 H $00 L $00 SP 23fe
01e9 LXI    H,#$2000	.....  A $00 B $00 C $00 D $1b E $00 H $20 L $00 SP 23fe
01ec JMP    $1a32	.....  A $00 B $00 C $00 D $1b E $00 H $20 L $00 SP 23fe
1a32 LDAX   D	.....  A $01 B $00 C $00 D $1b E $00 H $20 L $00 SP 23fe
1a33 MOV    M,A	.....  A $01 B $00 C $00 D $1b E $00 H $20 L $00 SP 23fe
1a34 INX    H	.....  A $01 B $00 C $00 D $1b E $00 H $20 L $01 SP 23fe
1a35 INX    D	.....  A $01 B $00 C $00 D $1b E $01 H $20 L $01 SP 23fe
1a36 DCR    B	.sp..  A $01 B $ff C $00 D $1b E $01 H $20 L $01 SP 23fe
1a37 JNZ    $1a32	.sp..  A $01 B $ff C $00 D $1b E $01 H $20 L $01 SP 23fe
1a32 LDAX   D	.sp..  A $00 B $ff C $00 D $1b E $01 H $20 L $01 SP 23fe
1a33 MOV    M,A	.sp..  A $00 B $ff C $00 D $1b E $01 H $20 L $01 SP 23fe
1a34 INX    H	.sp..  A $00 B $ff C $00 D $1b E $01 H $20 L $02 SP 23fe
1a35 INX    D	.sp..  A $00 B $ff C $00 D $1b E $02 H $20 L $02 SP 23fe
1a36 DCR    B	.s...  A $00 B $fe C $00 D $1b E $02 H $20 L $02 SP 23fe
1a37 JNZ    $1a32	.s...  A $00 B $fe C $00 D $1b E $02 H $20 L $02 SP 23fe
1a32 LDAX   D	.s...  A $00 B $fe C $00 D $1b E $02 H $20 L $02 SP 23fe
1a33 MOV    M,A	.s...  A $00 B $fe C $00 D $1b E $02 H $20 L $02 SP 23fe
1a34 INX    H	.s...  A $00 B $fe C $00 D $1b E $02 H $20 L $03 SP 23fe
1a35 INX    D	.s...  A $00 B $fe C $00 D $1b E $03 H $20 L $03 SP 23fe
1a36 DCR    B	.s...  A $00 B $fd C $00 D $1b E $03 H $20 L $03 SP 23fe
1a37 JNZ    $1a32	.s...  A $00 B $fd C $00 D $1b E $03 H $20 L $03 SP 23fe
1a32 LDAX   D	.s...  A $10 B $fd C $00 D $1b E $03 H $20 L $03 SP 23fe
1a33 MOV    M,A	.s...  A $10 B $fd C $00 D $1b E $03 H $20 L $03 SP 23fe
1a34 INX    H	.s...  A $10 B $fd C $00 D $1b E $03 H $20 L $04 SP 23fe
1a35 INX    D	.s...  A $10 B $fd C $00 D $1b E $04 H $20 L $04 SP 23fe
1a36 DCR    B	.sp..  A $10 B $fc C $00 D $1b E $04 H $20 L $04 SP 23fe
1a37 JNZ    $1a32	.sp..  A $10 B $fc C $00 D $1b E $04 H $20 L $04 SP 23fe
1a32 LDAX   D	.sp..  A $00 B $fc C $00 D $1b E $04 H $20 L $04 SP 23fe
1a33 MOV    M,A	.sp..  A $00 B $fc C $00 D $1b E $04 H $20 L $04 SP 23fe
1a34 INX    H	.sp..  A $00 B $fc C $00 D $1b E $04 H $20 L $05 SP 23fe
1a35 INX    D	.sp..  A $00 B $fc C $00 D $1b E $05 H $20 L $05 SP 23fe
1a36 DCR    B	.s...  A $00 B $fb C $00 D $1b E $05 H $20 L $05 SP 23fe
1a37 JNZ    $1a32	.s...  A $00 B $fb C $00 D $1b E $05 H $20 L $05 SP 23fe
1a32 LDAX   D	.s...  A $00 B $fb C $00 D $1b E $05 H $20 L $05 SP 23fe
1a33 MOV    M,A	.s...  A $00 B $fb C $00 D $1b E $05 H $20 L $05 SP 23fe
1a34 INX    H	.s...  A $00 B $fb C $00 D $1b E $05 H $20 L $06 SP 23fe
1a35 INX    D	.s...  A $00 B $fb C $00 D $1b E $06 H $20 L $06 SP 23fe
1a36 DCR    B	.sp..  A $00 B $fa C $00 D $1b E $06 H $20 L $06 SP 23fe

I guess Im wondering if the Dissassembly should cap itself or exit after a certain amount of time and condition? In the documents and sites you shared as resources, there was quite a bit of codes I ended up receiving that aren't listed anywhere. STA $20c0 - I did not see any STA opcodes.

Just wondered what my expectations should be and how to properly disassemble and understand how to use the debugger for such things.

at first we stepped through with break points, but after that we were expected to try and "run" the program and capture the results, and the only way I knew how to do this was by running the GDB and capturing the output. Was there another way to properly do this? Should I just be running ./test.out and then it would know to load my invaders files?

I created the invaders (packed) and also have the individual invaders.h/g/etc files in the same directory. I wasn't sure how to tell the program to 'run invaders' other than entering GDB and writing the command.

initial compilation error with the project

perhaps this is rather rudimentary yet these two missing file errors is what I am getting...

error: /Users/mvelicangil/Desktop/emulator_i8080_xcode/emulator101-master-3/CocoaPart3-Attract/Invaders/invaders.e: No such file or directory

and

error: /Users/mvelicangil/Desktop/emulator_i8080_xcode/emulator101-master-3/CocoaPart3-Attract/Invaders/invaders.f: No such file or directory

along with

red alerts for invaders.h and invaders.g under the supporting files...
where only main.m resides

Spelling mistakes in the 8080 tutorial

  • The link to github is http:// instead of https://, so the link is dead.
  • The verb "effect" should be replaced with "affect" throughout all the pages.

Great guide overall, thanks!

possible mistakes in 8080 reference

Reported on disqus/twitter:

the reference for CALL specifies SP<-SP+2, but comparing with the JS emulator I believe it should actually be SP<-SP-2

Typo: 0x26 should be: "H <- byte 2"

Mistake in chip8dis.c

on line 32:
uint8_t lastnib = code[1]>>4;
should be changed to :
uint8_t lastnib = code[1] & 0x0f;
because we are getting the second half of the second byte of code. The currrent code gets the first half of the last byte. So when opcode 8AB1 is called, we want to get that last "1" to show that we need to do a bitwise OR operation (VA = VA | VB). Currently, the code would get "B" as the lastnib.

Mistake in PUSH PSW

As per the intel manual, memory[stack pointer] bit 1 should be always set. Now it is always reset, similarly to bits 3 and 5.

CMC implementation is incorrect

All the variants of the emulator files have CMC (Complement Carry) implemented as "clear carry":

case 0x3f: state->cc.cy = 0; break;

It seems the test program (cpudiag.asm) does not catch that specific error and will pass the CPU as operational because it only checks that CMC results in the carry being set from 1 to 0:

STC
CNC	CPUER	;TEST "STC"
CMC
CC	CPUER	;TEST "CMC

CHIP-8 stack is in screen

While I appreciate the idea of having screen and stack in CHIP-8 memory like in the original CHIP-8, the init code sets the stack pointer to 0xFA0 and the screen to 0xF00. The screen is where it would be on a 4k COSMAC VIP, no issue with that, but the stack is inside the screen, so drawing and subroutine calls would interfere with each other.
My guess is, the 0xFA0 are a typo and might have meant to be 0xEA0, which is the start of the stack on the COSMACVIP, but as the stack of this implementation grows from the upper end downwards, it would need to start with a stack pointer of 0xED0, like the original.

Working on an equivalent in Swift - Issue with buffer creation for display

Hi

I don't know how to contact you as your twitter account seem to be disabled
I'm working on a swift equivalent of your work.
I found the tuto amazing and followed it step by step, now I can't seem to translate or even write the code for screen display, the resulting image is garbage.

Would you be able to help me? I can give the code in Swift so others can reuse it. It's an academic project to prepare a course for students.

Thanks a lot in advance.
[email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.