CHIP8 thread

Discussion in 'Web development / Programming' started by Dax, Nov 21, 2008.

  1. zodab12

    zodab12 New Member

    Messages:
    4
    Likes Received:
    0
    We programmed an IJVM assembler is class so that all of the hex values were outputted as they would normally appear on paper. I assumed that the roms would look quite similar. That's what led me astray.
  2. omegadox

    omegadox Code it the hard way :P

    Messages:
    1,267
    Likes Received:
    0
    Last edited: Jan 17, 2011
  3. janiczek

    janiczek New Member

    Messages:
    4
    Likes Received:
    0
    Hi guys,
    what happens if I draw something out of boundary?
    E.g. V0 = 60, V1 = 10, draw at (V0,V1)
    Do the 5 columns on the right overflow to the left or they get ignored?
  4. omegadox

    omegadox Code it the hard way :P

    Messages:
    1,267
    Likes Received:
    0
    My emulator masks the x and y values so the game can't ever drawing outside the boundaries but wrap still supported.
  5. janiczek

    janiczek New Member

    Messages:
    4
    Likes Received:
    0
    Thanks. I didn't think of a way to *mask* it, but I can calculate it ...

    if VX > 63 or VY > 31
    return 0
    # skip the drawing loop

    if VX > 56
    x_stripped = 64 - VX
    else
    x_stripped = 8

    if VY > (32 - height)
    y_stripped = 32 - VY
    else
    y_stripped = height

    # instead of
    # for col in [0 ... 8]
    # for row in [0 ... height]
    for col in [0 ... x_stripped]
    for row in [0 ... y_stripped]
    # rest

    Didn't test it though, but when I'll get home, I'll do that ...
    Last edited: Jan 18, 2011
  6. omegadox

    omegadox Code it the hard way :P

    Messages:
    1,267
    Likes Received:
    0
    That would be wrapping but the game Syzygy, draws one border off screen, if it wraps, it will wrap around and collide with the existing border causing part of it turn black.

    You want to mask x and y like:
    PixelSet(this, new PixelSetEventArgs((x + j) & 0x3F, (y + i) & 0x1F));

    HTH
  7. xneoangel

    xneoangel New Member

    Messages:
    8
    Likes Received:
    0
    Hello there guys,

    I've been interested in emu development since a long time ago, but i only started to learn some programming about 2 years ago, and well i think i'm ready for my first emu project "jChips" yet another chip-8 emulator in java :lol:

    I also know some c/c++ and c#, but i decided to use java because i know how to do some graphics in it with the classic Graphics class, i also know some GDI+ with c# but i like portability so java was the obvious choice.

    Anyways i've spent the last 2 days reading documentation on the system, and this thread and also emutalk's thread. I think i already have what i need to start coding and i also have a rough design on my head.

    But, there's always a but :lol:, there are a couple of things that bother me, hope you guys can clarify this doubts for me.

    1) The font set, where should i store it? on any of the "reserved/actuallyempty" space for the interpreter (0x000-0x200)?

    2) This question is actually more java oriented... i've made a little function to load the rom into memory but i'm not quite sure if i got it right, since i can see a couple of invalid opcodes if i do a memory dump(crappily printing the file as i read it as you'll see on the code)... i'm guessing those invalid opcodes are actually sprites for the game but i'm not sure...

    Anyways here's my function:

    Yes i know i'm using a static rom name as of right now... but this is just for testing purposes i'll use a JFileChooser later...

    and
    3) Again a java oriented question... since there are no unsigned data types in java are ints (32-bit >.<, what i'm currently using) the most effective way of representing memory/registers or should i use a different data type?

    And that's all folks,
    Thanks for reading my long post :D
  8. Dax

    Dax ライチュウ|タオ

    Messages:
    4,016
    Likes Received:
    20
    Keep the font at 0x0000[just 0], it'll be a lot easier on you in the end when you have to calculate the offset to each font character(if it's at 0, it's register I * 5, because each character is 5 bytes). I haven't programmed in Java since High school, so I can't help much there. You don't have to worry about putting it at 0 because on the old computers that had a chip8 interpreter, they put the interpreter code there. Since that's irrelevant here, you can use 0 for whatever you want. I suggest the font.
  9. Bill_gates

    Bill_gates Linux's worst nightmare..

    Messages:
    1,510
    Likes Received:
    0
    chars in java are unsigned and 16 bits long. I used the hell out of them when i wrote my chip 8 emu ;)
  10. xneoangel

    xneoangel New Member

    Messages:
    8
    Likes Received:
    0
    Hmm ok then the font set would start at 0x000 and i'll be using chars as my registers/memory... thanks guys i'm gonna start writing the core now :p

    I'll let ya know if i make any progress or if i get stuck aimlessly :lol:
  11. Bill_gates

    Bill_gates Linux's worst nightmare..

    Messages:
    1,510
    Likes Received:
    0
    sounds like a plan keep us posted
  12. runawayprisoner

    runawayprisoner Level 9998

    Messages:
    9,384
    Likes Received:
    0
    Better to use int if you want to take advantage of the various bit and binary tricks that ensue. Use char or any other data type only if you are worried about your application hogging memory.

    Also it's easier to use int to do various bit-wise operations since it's 32-bit, and practically, you can use it as a 31-bit unsigned data type. Anything that can store more than 16-bit is recommended for operations that wrap bits around or do anything as crazy as that. Plus math operations would be straight-forward.
  13. xneoangel

    xneoangel New Member

    Messages:
    8
    Likes Received:
    0
    I'm currently working on the arithmetic opcodes but i kinda have a doubt...
    what happens to the registers involved on an arithmetic operation when there's carry or borrow?
    i.e: V0 = V0 + V2 > 255
    should i make V0 = 255 in this case?
    V0 = V0 - V2 < 0
    should i make V0 = 0 in this case?
    also shoouldn't i activate the carry flag on opcode 7XKK? no documentation tells me too but it seems logical to me that it should be activated if there's an overflow...
  14. Bill_gates

    Bill_gates Linux's worst nightmare..

    Messages:
    1,510
    Likes Received:
    0
    chars are perfectly sufficient for this. using ints and saying "i'll just use the lower 31 bits" is asking for trouble especially considering hes a beginner.
  15. Dax

    Dax ライチュウ|タオ

    Messages:
    4,016
    Likes Received:
    20
    When an unsigned number(a number that's never negative, like 0-255 for a byte) becomes < 0 or > MaxValue(8bit: 255, 16bit:65535, etc.), it wraps around. Say you have 255 + 1. It'll become 0. Or say you have 2 - 3. It'll become 255. When conditions like these happen, that's when the carry/borrow flags get set. Hope I explained that okay.

    If that still doesn't make any sense, look at it this way in binary:

    255 = 0xFF = 1111 1111
    + 1 = 0x01 = 0000 0001
    ----------------------------
    256 = 0x100 = 1 0000 0000

    Since the 1[that ninth bit in 256] "doesn't exist" in an 8bit byte anymore, it wraps around to 0. Does that help?
    Last edited: Feb 27, 2011
  16. xneoangel

    xneoangel New Member

    Messages:
    8
    Likes Received:
    0
    Hmm ok but just to clarify because those examples are kinda special cases that could lead me to believe that when there's borrow make the register MAXVALUE and when there's carry make your register 0... i think that's not the case but i just wanna be sure, by wrap around you mean...

    2 - 4 = 254, 2 - 5 = 253...
    255 + 2 = 1, 255 + 3 = 2...

    and so on and so forth... that's what you mean right?
    and what about the carry flag on opcode 7XKK? it's bothering me since quite a while...
  17. Dax

    Dax ライチュウ|タオ

    Messages:
    4,016
    Likes Received:
    20
    You're right on the money with the examples you came up with. As for the carry flag on 7XKK, I don't believe it affects the flag at all.
  18. omegadox

    omegadox Code it the hard way :P

    Messages:
    1,267
    Likes Received:
    0
    Dax is right, I don't think Add7 has carry. Here is source of my code:

    [OpcodeTag(ChipOpCode.Add_7)]
    void Add_7(ChipInstruction inst)
    {
    m_VRegs[inst.X] += inst.KK;
    }

    @Dax: So where is that chip8 IL dynarec? :p
  19. runawayprisoner

    runawayprisoner Level 9998

    Messages:
    9,384
    Likes Received:
    0
    I don't doubt the efficiency or usefulness of chars. In fact, I'd recommend it any day, if only the subject didn't involve emulation.

    I was merely suggesting int because when it starts getting deeper, int will exceed char in storage capability, and that's kind of useful in situations where you need to record memory footprint and/or access history transparently of the current memory space and without introducing further memory usage to the system while still retaining the ability to code in further features. ;)

    Plus I was thinking he'll end up having to use ints or even longs for other emulators as he advances, so it'd be good for him to have some experience handling ints first.
  20. omegadox

    omegadox Code it the hard way :P

    Messages:
    1,267
    Likes Received:
    0
    Sometime I will port my emulator too Android which means Java, I'd probably write a class called UInt16, and inside override the operators and make it safely store unsigned 16bit data in an array or something.

Share This Page