[LIB] Chip8 Renderer [Windows x64]

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
Mijikai
Beiträge: 754
Registriert: 25.09.2016 01:42

[LIB] Chip8 Renderer [Windows x64]

Beitrag von Mijikai »

Ein kleine sehr einfache (in fasm geschriebene) Render Library für ein Chip8 Projekt oder andere kleine Spiele.

Features:
- automatische Anpassung der Renderausgabe an die Fenster- / Gadgetgröße (Seitenverhältnis wird berücksichtigt)
- eigene Farben (oder ganze Farbpaletten) für den Hinter- und Vordergrund / oder direkte per Pixel Farben
- Zeitgeber (16 ms Takt) für das Rendern bzw. als Timer für den Chip8 (CPU freundlich)
- Pixel Zeichenfunktionen mit und ohne Überprüfung der Eingabeparameter

Die Auflösung ist fix und beträgt gemäß Chip8 Spezifikation: 64 x 32 Pixel!

Beispiel:

Code: Alles auswählen

;CHIP8DIB - A SMALL DIB RENDERER FOR A CHIP8 PROJECT
;AUTHOR: MIJIKAI
;VERSION: 1.2

EnableExplicit

Import "chip8dib.lib";v.1.2
  chip8CreateDIB.i(hwnd.i)
EndImport

Interface CHIP8DIB
  Clear.i();clear the backbuffer
  Pixel.i(X.i,Y.i);draws a pixel to the backbuffer using the palette color or single color set
  PixelTest.i(X.i,Y.i);also draws a pixel but checks the boundaries!
  PixelColor.i(X.i,Y.i,Color.i);draws a pixel using the color selected
  PixelColorTest.i(X.i,Y.i,Color.i)
  Blit.i();flips the buffers
  Color.i(Color.i,Type.i = #Null,Flag.i = #Null);color = color value or pointer to palette / if type = 0 -> upload palette; type = 1 -> set color / flag = 0 back- flag = 1 foreground
  Resize.i();autmatically adjust the ouput to the host size - gadget or window!
  Clock.i()
  Release.i();release all resources
EndInterface

Procedure.i Chip8UploadPalette(*chip8dib.CHIP8DIB,Flag.i)
  *chip8dib\Color(?chip8_color,0,Flag)
  ProcedureReturn #Null
  chip8_color:;palette = 64 x 32 colors!
  !dd 0xFF009176,0xFF009377,0xFF009477,0xFF009578,0xFF009778,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A27D,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A87F,0xFF00A980,0xFF00AA80,0xFF00AB80,0xFF00AC81,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00AE82,0xFF00AF82,0xFF00AF82,0xFF00AF82,0xFF00B082,0xFF00B082,0xFF00B082,0xFF00B082,0xFF00AF82,0xFF00AF82,0xFF00AF82,0xFF00AE82,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AC81,0xFF00AB80,0xFF00AA80,0xFF00A980,0xFF00A87F,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A27D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009C7A,0xFF009B7A,0xFF009979,0xFF009879,0xFF009778,0xFF009578,0xFF009477,0xFF009377,0xFF009176
  !dd 0xFF009276,0xFF009377,0xFF009477,0xFF009678,0xFF009879,0xFF009979,0xFF009A7A,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A27D,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A87F,0xFF00A980,0xFF00AA80,0xFF00AB80,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00AE82,0xFF00AF82,0xFF00B082,0xFF00B083,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B083,0xFF00B082,0xFF00AF82,0xFF00AE82,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AB80,0xFF00AA80,0xFF00A980,0xFF00A87F,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A27D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009A7A,0xFF009979,0xFF009879,0xFF009678,0xFF009477,0xFF009377,0xFF009276
  !dd 0xFF009277,0xFF009477,0xFF009578,0xFF009778,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7A,0xFF009E7B,0xFF009F7C,0xFF00A07C,0xFF00A27D,0xFF00A37D,0xFF00A47E,0xFF00A57E,0xFF00A77F,0xFF00A87F,0xFF00A980,0xFF00AA80,0xFF00AB81,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00AF82,0xFF00B082,0xFF00B183,0xFF00B183,0xFF00B283,0xFF00B283,0xFF00B383,0xFF00B384,0xFF00B384,0xFF00B384,0xFF00B384,0xFF00B383,0xFF00B283,0xFF00B283,0xFF00B183,0xFF00B183,0xFF00B082,0xFF00AF82,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AB81,0xFF00AA80,0xFF00A980,0xFF00A87F,0xFF00A77F,0xFF00A57E,0xFF00A47E,0xFF00A37D,0xFF00A27D,0xFF00A07C,0xFF009F7C,0xFF009E7B,0xFF009C7A,0xFF009B7A,0xFF009979,0xFF009879,0xFF009778,0xFF009578,0xFF009477,0xFF009377
  !dd 0xFF009377,0xFF009477,0xFF009678,0xFF009778,0xFF009979,0xFF009A7A,0xFF009C7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A37D,0xFF00A47D,0xFF00A57E,0xFF00A67F,0xFF00A77F,0xFF00A980,0xFF00AA80,0xFF00AB81,0xFF00AC81,0xFF00AE81,0xFF00AE82,0xFF00AF82,0xFF00B083,0xFF00B183,0xFF00B283,0xFF00B383,0xFF00B384,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B384,0xFF00B383,0xFF00B283,0xFF00B183,0xFF00B083,0xFF00AF82,0xFF00AE82,0xFF00AE81,0xFF00AC81,0xFF00AB81,0xFF00AA80,0xFF00A980,0xFF00A77F,0xFF00A67F,0xFF00A57E,0xFF00A47D,0xFF00A37D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009C7A,0xFF009A7A,0xFF009979,0xFF009778,0xFF009678,0xFF009477,0xFF009377
  !dd 0xFF009477,0xFF009578,0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7A,0xFF009E7B,0xFF009F7C,0xFF00A17C,0xFF00A27D,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A97F,0xFF00AA80,0xFF00AB80,0xFF00AC81,0xFF00AE81,0xFF00AF82,0xFF00B082,0xFF00B183,0xFF00B283,0xFF00B383,0xFF00B384,0xFF00B484,0xFF00B584,0xFF00B585,0xFF00B685,0xFF00B685,0xFF00B685,0xFF00B685,0xFF00B685,0xFF00B685,0xFF00B585,0xFF00B584,0xFF00B484,0xFF00B384,0xFF00B383,0xFF00B283,0xFF00B183,0xFF00B082,0xFF00AF82,0xFF00AE81,0xFF00AC81,0xFF00AB80,0xFF00AA80,0xFF00A97F,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A27D,0xFF00A17C,0xFF009F7C,0xFF009E7B,0xFF009C7A,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678,0xFF009578,0xFF009477
  !dd 0xFF009477,0xFF009678,0xFF009778,0xFF009879,0xFF009A7A,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A37D,0xFF00A47E,0xFF00A57E,0xFF00A77F,0xFF00A87F,0xFF00A980,0xFF00AB80,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00B082,0xFF00B183,0xFF00B283,0xFF00B384,0xFF00B484,0xFF00B584,0xFF00B685,0xFF00B685,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B685,0xFF00B685,0xFF00B584,0xFF00B484,0xFF00B384,0xFF00B283,0xFF00B183,0xFF00B082,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AB80,0xFF00A980,0xFF00A87F,0xFF00A77F,0xFF00A57E,0xFF00A47E,0xFF00A37D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009A7A,0xFF009979,0xFF009778,0xFF009678,0xFF009477
  !dd 0xFF009477,0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7A,0xFF009D7B,0xFF009F7C,0xFF00A07C,0xFF00A27D,0xFF00A37D,0xFF00A57E,0xFF00A67E,0xFF00A77F,0xFF00A980,0xFF00AA80,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00AF82,0xFF00B183,0xFF00B283,0xFF00B384,0xFF00B484,0xFF00B584,0xFF00B685,0xFF00B785,0xFF00B785,0xFF00B886,0xFF00B986,0xFF00B986,0xFF00B986,0xFF00B986,0xFF00B986,0xFF00B986,0xFF00B886,0xFF00B785,0xFF00B785,0xFF00B685,0xFF00B584,0xFF00B484,0xFF00B384,0xFF00B283,0xFF00B183,0xFF00AF82,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AA80,0xFF00A980,0xFF00A77F,0xFF00A67E,0xFF00A57E,0xFF00A37D,0xFF00A27D,0xFF00A07C,0xFF009F7C,0xFF009E7B,0xFF009C7A,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678,0xFF009477
  !dd 0xFF009578,0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A27D,0xFF00A47E,0xFF00A57E,0xFF00A77F,0xFF00A87F,0xFF00A980,0xFF00AB80,0xFF00AC81,0xFF00AE82,0xFF00AF82,0xFF00B083,0xFF00B283,0xFF00B384,0xFF00B484,0xFF00B585,0xFF00B685,0xFF00B785,0xFF00B886,0xFF00B986,0xFF00BA86,0xFF00BA86,0xFF00BB87,0xFF00BB87,0xFF00BB87,0xFF00BB87,0xFF00BA86,0xFF00BA86,0xFF00B986,0xFF00B886,0xFF00B785,0xFF00B685,0xFF00B585,0xFF00B484,0xFF00B384,0xFF00B283,0xFF00B083,0xFF00AF82,0xFF00AE82,0xFF00AC81,0xFF00AB80,0xFF00AA80,0xFF00A87F,0xFF00A77F,0xFF00A57E,0xFF00A47E,0xFF00A27D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009C7B,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678,0xFF009578
  !dd 0xFF009578,0xFF009778,0xFF009879,0xFF009A7A,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17D,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A980,0xFF00AA80,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00B082,0xFF00B183,0xFF00B383,0xFF00B484,0xFF00B584,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00B986,0xFF00BA86,0xFF00BB87,0xFF00BC87,0xFF00BC87,0xFF00BC87,0xFF00BC87,0xFF00BC87,0xFF00BC87,0xFF00BB87,0xFF00BA86,0xFF00B986,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B584,0xFF00B484,0xFF00B383,0xFF00B183,0xFF00B082,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AA80,0xFF00A980,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A17D,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009A7A,0xFF009879,0xFF009778,0xFF009578
  !dd 0xFF009678,0xFF009778,0xFF009979,0xFF009A7A,0xFF009C7A,0xFF009D7B,0xFF009F7C,0xFF00A07C,0xFF00A27D,0xFF00A37D,0xFF00A57E,0xFF00A67F,0xFF00A87F,0xFF00A980,0xFF00AB80,0xFF00AC81,0xFF00AE82,0xFF00AF82,0xFF00B183,0xFF00B283,0xFF00B384,0xFF00B584,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00BA86,0xFF00BB87,0xFF00BC87,0xFF00BC87,0xFF00BD88,0xFF00BE88,0xFF00BE88,0xFF00BE88,0xFF00BE88,0xFF00BD88,0xFF00BC87,0xFF00BC87,0xFF00BB87,0xFF00BA86,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B584,0xFF00B384,0xFF00B283,0xFF00B183,0xFF00AF82,0xFF00AE82,0xFF00AC81,0xFF00AB80,0xFF00A980,0xFF00A87F,0xFF00A67F,0xFF00A57E,0xFF00A37D,0xFF00A27D,0xFF00A07C,0xFF009F7C,0xFF009D7B,0xFF009C7A,0xFF009A7A,0xFF009979,0xFF009778,0xFF009678
  !dd 0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7A,0xFF009E7B,0xFF009F7C,0xFF00A17C,0xFF00A27D,0xFF00A47D,0xFF00A57E,0xFF00A77F,0xFF00A87F,0xFF00AA80,0xFF00AB81,0xFF00AD81,0xFF00AE82,0xFF00B082,0xFF00B183,0xFF00B383,0xFF00B484,0xFF00B685,0xFF00B785,0xFF00B886,0xFF00B986,0xFF00BB87,0xFF00BC87,0xFF00BD88,0xFF00BE88,0xFF00BF88,0xFF00BF88,0xFF00BF89,0xFF00BF89,0xFF00BF88,0xFF00BF88,0xFF00BE88,0xFF00BD88,0xFF00BC87,0xFF00BB87,0xFF00B986,0xFF00B886,0xFF00B785,0xFF00B685,0xFF00B484,0xFF00B384,0xFF00B183,0xFF00B082,0xFF00AE82,0xFF00AD81,0xFF00AB81,0xFF00AA80,0xFF00A87F,0xFF00A77F,0xFF00A57E,0xFF00A47D,0xFF00A27D,0xFF00A17C,0xFF009F7C,0xFF009E7B,0xFF009C7A,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678
  !dd 0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A97F,0xFF00AA80,0xFF00AC81,0xFF00AD81,0xFF00AF82,0xFF00B083,0xFF00B283,0xFF00B384,0xFF00B584,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00BA86,0xFF00BC87,0xFF00BD88,0xFF00BE88,0xFF00BF88,0xFF00C089,0xFF00C189,0xFF00C189,0xFF00C189,0xFF00C189,0xFF00C089,0xFF00BF88,0xFF00BE88,0xFF00BD88,0xFF00BC87,0xFF00BA86,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B584,0xFF00B384,0xFF00B283,0xFF00B083,0xFF00AF82,0xFF00AD81,0xFF00AC81,0xFF00AA80,0xFF00A97F,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009C7B,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678
  !dd 0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A980,0xFF00AB80,0xFF00AC81,0xFF00AE81,0xFF00AF82,0xFF00B183,0xFF00B283,0xFF00B484,0xFF00B585,0xFF00B785,0xFF00B886,0xFF00BA86,0xFF00BB87,0xFF00BC87,0xFF00BE88,0xFF00BF88,0xFF00C089,0xFF00C189,0xFF00C28A,0xFF00C28A,0xFF00C28A,0xFF00C28A,0xFF00C189,0xFF00C089,0xFF00BF88,0xFF00BE88,0xFF00BC87,0xFF00BB87,0xFF00BA86,0xFF00B886,0xFF00B785,0xFF00B585,0xFF00B484,0xFF00B283,0xFF00B183,0xFF00AF82,0xFF00AE81,0xFF00AC81,0xFF00AB80,0xFF00A980,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678
  !dd 0xFF009778,0xFF009879,0xFF009A79,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17D,0xFF00A37D,0xFF00A57E,0xFF00A67E,0xFF00A87F,0xFF00A980,0xFF00AB80,0xFF00AC81,0xFF00AE82,0xFF00AF82,0xFF00B183,0xFF00B383,0xFF00B484,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00BA86,0xFF00BC87,0xFF00BD88,0xFF00BF88,0xFF00C089,0xFF00C189,0xFF00C28A,0xFF00C38A,0xFF00C48A,0xFF00C48A,0xFF00C38A,0xFF00C28A,0xFF00C189,0xFF00C089,0xFF00BF88,0xFF00BD88,0xFF00BC87,0xFF00BA86,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B484,0xFF00B383,0xFF00B183,0xFF00AF82,0xFF00AE82,0xFF00AC81,0xFF00AB80,0xFF00A980,0xFF00A87F,0xFF00A67E,0xFF00A57E,0xFF00A37D,0xFF00A17D,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009A79,0xFF009879,0xFF009778
  !dd 0xFF009778,0xFF009879,0xFF009A79,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A27D,0xFF00A37D,0xFF00A57E,0xFF00A67F,0xFF00A87F,0xFF00A980,0xFF00AB80,0xFF00AC81,0xFF00AE82,0xFF00B082,0xFF00B183,0xFF00B384,0xFF00B484,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00BB87,0xFF00BC87,0xFF00BE88,0xFF00BF88,0xFF00C189,0xFF00C28A,0xFF00C38A,0xFF00C58B,0xFF00C68B,0xFF00C68B,0xFF00C58B,0xFF00C38A,0xFF00C28A,0xFF00C189,0xFF00BF88,0xFF00BE88,0xFF00BC87,0xFF00BB87,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B484,0xFF00B384,0xFF00B183,0xFF00B082,0xFF00AE82,0xFF00AC81,0xFF00AB80,0xFF00A980,0xFF00A87F,0xFF00A67F,0xFF00A57E,0xFF00A37D,0xFF00A27D,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009A79,0xFF009879,0xFF009778
  !dd 0xFF009778,0xFF009879,0xFF009A7A,0xFF009B7A,0xFF009D7B,0xFF009F7B,0xFF00A07C,0xFF00A27D,0xFF00A37D,0xFF00A57E,0xFF00A67F,0xFF00A87F,0xFF00A980,0xFF00AB80,0xFF00AD81,0xFF00AE82,0xFF00B082,0xFF00B183,0xFF00B384,0xFF00B484,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00BB87,0xFF00BC87,0xFF00BE88,0xFF00BF89,0xFF00C189,0xFF00C28A,0xFF00C48A,0xFF00C68B,0xFF00C78C,0xFF00C78C,0xFF00C68B,0xFF00C48A,0xFF00C28A,0xFF00C189,0xFF00BF89,0xFF00BE88,0xFF00BC87,0xFF00BB87,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B484,0xFF00B384,0xFF00B183,0xFF00B082,0xFF00AE82,0xFF00AD81,0xFF00AB80,0xFF00A980,0xFF00A87F,0xFF00A67F,0xFF00A57E,0xFF00A37D,0xFF00A27D,0xFF00A07C,0xFF009F7B,0xFF009D7B,0xFF009B7A,0xFF009A7A,0xFF009879,0xFF009778
  !dd 0xFF009778,0xFF009879,0xFF009A7A,0xFF009B7A,0xFF009D7B,0xFF009F7B,0xFF00A07C,0xFF00A27D,0xFF00A37D,0xFF00A57E,0xFF00A67F,0xFF00A87F,0xFF00A980,0xFF00AB80,0xFF00AD81,0xFF00AE82,0xFF00B082,0xFF00B183,0xFF00B384,0xFF00B484,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00BB87,0xFF00BC87,0xFF00BE88,0xFF00BF89,0xFF00C189,0xFF00C28A,0xFF00C48A,0xFF00C68B,0xFF00C78C,0xFF00C78C,0xFF00C68B,0xFF00C48A,0xFF00C28A,0xFF00C189,0xFF00BF89,0xFF00BE88,0xFF00BC87,0xFF00BB87,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B484,0xFF00B384,0xFF00B183,0xFF00B082,0xFF00AE82,0xFF00AD81,0xFF00AB80,0xFF00A980,0xFF00A87F,0xFF00A67F,0xFF00A57E,0xFF00A37D,0xFF00A27D,0xFF00A07C,0xFF009F7B,0xFF009D7B,0xFF009B7A,0xFF009A7A,0xFF009879,0xFF009778
  !dd 0xFF009778,0xFF009879,0xFF009A79,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A27D,0xFF00A37D,0xFF00A57E,0xFF00A67F,0xFF00A87F,0xFF00A980,0xFF00AB80,0xFF00AC81,0xFF00AE82,0xFF00B082,0xFF00B183,0xFF00B384,0xFF00B484,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00BB87,0xFF00BC87,0xFF00BE88,0xFF00BF88,0xFF00C189,0xFF00C28A,0xFF00C38A,0xFF00C58B,0xFF00C68B,0xFF00C68B,0xFF00C58B,0xFF00C38A,0xFF00C28A,0xFF00C189,0xFF00BF88,0xFF00BE88,0xFF00BC87,0xFF00BB87,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B484,0xFF00B384,0xFF00B183,0xFF00B082,0xFF00AE82,0xFF00AC81,0xFF00AB80,0xFF00A980,0xFF00A87F,0xFF00A67F,0xFF00A57E,0xFF00A37D,0xFF00A27D,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009A79,0xFF009879,0xFF009778
  !dd 0xFF009778,0xFF009879,0xFF009A79,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17D,0xFF00A37D,0xFF00A57E,0xFF00A67E,0xFF00A87F,0xFF00A980,0xFF00AB80,0xFF00AC81,0xFF00AE82,0xFF00AF82,0xFF00B183,0xFF00B383,0xFF00B484,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00BA86,0xFF00BC87,0xFF00BD88,0xFF00BF88,0xFF00C089,0xFF00C189,0xFF00C28A,0xFF00C38A,0xFF00C48A,0xFF00C48A,0xFF00C38A,0xFF00C28A,0xFF00C189,0xFF00C089,0xFF00BF88,0xFF00BD88,0xFF00BC87,0xFF00BA86,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B484,0xFF00B383,0xFF00B183,0xFF00AF82,0xFF00AE82,0xFF00AC81,0xFF00AB80,0xFF00A980,0xFF00A87F,0xFF00A67E,0xFF00A57E,0xFF00A37D,0xFF00A17D,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009A79,0xFF009879,0xFF009778
  !dd 0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A980,0xFF00AB80,0xFF00AC81,0xFF00AE81,0xFF00AF82,0xFF00B183,0xFF00B283,0xFF00B484,0xFF00B585,0xFF00B785,0xFF00B886,0xFF00BA86,0xFF00BB87,0xFF00BC87,0xFF00BE88,0xFF00BF88,0xFF00C089,0xFF00C189,0xFF00C28A,0xFF00C28A,0xFF00C28A,0xFF00C28A,0xFF00C189,0xFF00C089,0xFF00BF88,0xFF00BE88,0xFF00BC87,0xFF00BB87,0xFF00BA86,0xFF00B886,0xFF00B785,0xFF00B585,0xFF00B484,0xFF00B283,0xFF00B183,0xFF00AF82,0xFF00AE81,0xFF00AC81,0xFF00AB80,0xFF00A980,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678
  !dd 0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A97F,0xFF00AA80,0xFF00AC81,0xFF00AD81,0xFF00AF82,0xFF00B083,0xFF00B283,0xFF00B384,0xFF00B584,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00BA86,0xFF00BC87,0xFF00BD88,0xFF00BE88,0xFF00BF88,0xFF00C089,0xFF00C189,0xFF00C189,0xFF00C189,0xFF00C189,0xFF00C089,0xFF00BF88,0xFF00BE88,0xFF00BD88,0xFF00BC87,0xFF00BA86,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B584,0xFF00B384,0xFF00B283,0xFF00B083,0xFF00AF82,0xFF00AD81,0xFF00AC81,0xFF00AA80,0xFF00A97F,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009C7B,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678
  !dd 0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7A,0xFF009E7B,0xFF009F7C,0xFF00A17C,0xFF00A27D,0xFF00A47D,0xFF00A57E,0xFF00A77F,0xFF00A87F,0xFF00AA80,0xFF00AB81,0xFF00AD81,0xFF00AE82,0xFF00B082,0xFF00B183,0xFF00B383,0xFF00B484,0xFF00B685,0xFF00B785,0xFF00B886,0xFF00B986,0xFF00BB87,0xFF00BC87,0xFF00BD88,0xFF00BE88,0xFF00BF88,0xFF00BF88,0xFF00BF89,0xFF00BF89,0xFF00BF88,0xFF00BF88,0xFF00BE88,0xFF00BD88,0xFF00BC87,0xFF00BB87,0xFF00B986,0xFF00B886,0xFF00B785,0xFF00B685,0xFF00B484,0xFF00B384,0xFF00B183,0xFF00B082,0xFF00AE82,0xFF00AD81,0xFF00AB81,0xFF00AA80,0xFF00A87F,0xFF00A77F,0xFF00A57E,0xFF00A47E,0xFF00A27D,0xFF00A17C,0xFF009F7C,0xFF009E7B,0xFF009C7A,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678
  !dd 0xFF009678,0xFF009778,0xFF009979,0xFF009A7A,0xFF009C7A,0xFF009D7B,0xFF009F7C,0xFF00A07C,0xFF00A27D,0xFF00A37D,0xFF00A57E,0xFF00A67F,0xFF00A87F,0xFF00A980,0xFF00AB80,0xFF00AC81,0xFF00AE82,0xFF00AF82,0xFF00B183,0xFF00B283,0xFF00B384,0xFF00B584,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00BA86,0xFF00BB87,0xFF00BC87,0xFF00BC87,0xFF00BD88,0xFF00BE88,0xFF00BE88,0xFF00BE88,0xFF00BE88,0xFF00BD88,0xFF00BC87,0xFF00BC87,0xFF00BB87,0xFF00BA86,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B584,0xFF00B384,0xFF00B283,0xFF00B183,0xFF00AF82,0xFF00AE82,0xFF00AC81,0xFF00AB80,0xFF00A980,0xFF00A87F,0xFF00A67F,0xFF00A57E,0xFF00A37D,0xFF00A27D,0xFF00A07C,0xFF009F7C,0xFF009D7B,0xFF009C7A,0xFF009A7A,0xFF009979,0xFF009778,0xFF009678
  !dd 0xFF009578,0xFF009778,0xFF009879,0xFF009A7A,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17D,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A980,0xFF00AA80,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00B082,0xFF00B183,0xFF00B383,0xFF00B484,0xFF00B584,0xFF00B685,0xFF00B785,0xFF00B986,0xFF00B986,0xFF00BA86,0xFF00BB87,0xFF00BC87,0xFF00BC87,0xFF00BC87,0xFF00BC87,0xFF00BC87,0xFF00BC87,0xFF00BB87,0xFF00BA86,0xFF00B986,0xFF00B986,0xFF00B785,0xFF00B685,0xFF00B584,0xFF00B484,0xFF00B383,0xFF00B183,0xFF00B082,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AA80,0xFF00A980,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A17D,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009A7A,0xFF009879,0xFF009778,0xFF009578
  !dd 0xFF009578,0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A27D,0xFF00A47E,0xFF00A57E,0xFF00A77F,0xFF00A87F,0xFF00AA80,0xFF00AB80,0xFF00AC81,0xFF00AE82,0xFF00AF82,0xFF00B083,0xFF00B283,0xFF00B384,0xFF00B484,0xFF00B585,0xFF00B685,0xFF00B785,0xFF00B886,0xFF00B986,0xFF00BA86,0xFF00BA86,0xFF00BB87,0xFF00BB87,0xFF00BB87,0xFF00BB87,0xFF00BA86,0xFF00BA86,0xFF00B986,0xFF00B886,0xFF00B785,0xFF00B685,0xFF00B585,0xFF00B484,0xFF00B384,0xFF00B283,0xFF00B083,0xFF00AF82,0xFF00AE82,0xFF00AC81,0xFF00AB80,0xFF00AA80,0xFF00A87F,0xFF00A77F,0xFF00A57E,0xFF00A47E,0xFF00A37D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009C7B,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678,0xFF009578
  !dd 0xFF009477,0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7A,0xFF009D7B,0xFF009F7C,0xFF00A07C,0xFF00A27D,0xFF00A37D,0xFF00A57E,0xFF00A67E,0xFF00A77F,0xFF00A980,0xFF00AA80,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00AF82,0xFF00B183,0xFF00B283,0xFF00B384,0xFF00B484,0xFF00B584,0xFF00B685,0xFF00B785,0xFF00B785,0xFF00B886,0xFF00B986,0xFF00B986,0xFF00B986,0xFF00B986,0xFF00B986,0xFF00B986,0xFF00B886,0xFF00B785,0xFF00B785,0xFF00B685,0xFF00B584,0xFF00B484,0xFF00B384,0xFF00B283,0xFF00B183,0xFF00AF82,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AA80,0xFF00A980,0xFF00A77F,0xFF00A67E,0xFF00A57E,0xFF00A37D,0xFF00A27D,0xFF00A07C,0xFF009F7C,0xFF009E7B,0xFF009C7A,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678,0xFF009477
  !dd 0xFF009477,0xFF009678,0xFF009778,0xFF009979,0xFF009A7A,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A37D,0xFF00A47E,0xFF00A57E,0xFF00A77F,0xFF00A87F,0xFF00A980,0xFF00AB80,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00B082,0xFF00B183,0xFF00B283,0xFF00B384,0xFF00B484,0xFF00B584,0xFF00B685,0xFF00B685,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B785,0xFF00B685,0xFF00B685,0xFF00B584,0xFF00B484,0xFF00B384,0xFF00B283,0xFF00B183,0xFF00B082,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AB80,0xFF00A980,0xFF00A87F,0xFF00A77F,0xFF00A57E,0xFF00A47E,0xFF00A37D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009A7A,0xFF009979,0xFF009778,0xFF009678,0xFF009477
  !dd 0xFF009477,0xFF009578,0xFF009678,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7A,0xFF009E7B,0xFF009F7C,0xFF00A17C,0xFF00A27D,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A97F,0xFF00AA80,0xFF00AB80,0xFF00AC81,0xFF00AE81,0xFF00AF82,0xFF00B082,0xFF00B183,0xFF00B283,0xFF00B383,0xFF00B384,0xFF00B484,0xFF00B584,0xFF00B585,0xFF00B685,0xFF00B685,0xFF00B685,0xFF00B685,0xFF00B685,0xFF00B685,0xFF00B585,0xFF00B584,0xFF00B484,0xFF00B384,0xFF00B383,0xFF00B283,0xFF00B183,0xFF00B082,0xFF00AF82,0xFF00AE81,0xFF00AC81,0xFF00AB80,0xFF00AA80,0xFF00A97F,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A27D,0xFF00A17C,0xFF009F7C,0xFF009E7B,0xFF009C7A,0xFF009B7A,0xFF009979,0xFF009879,0xFF009678,0xFF009578,0xFF009477
  !dd 0xFF009377,0xFF009477,0xFF009678,0xFF009778,0xFF009979,0xFF009A7A,0xFF009C7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A37D,0xFF00A47E,0xFF00A57E,0xFF00A67F,0xFF00A77F,0xFF00A980,0xFF00AA80,0xFF00AB81,0xFF00AC81,0xFF00AE81,0xFF00AE82,0xFF00AF82,0xFF00B083,0xFF00B183,0xFF00B283,0xFF00B384,0xFF00B384,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B484,0xFF00B384,0xFF00B384,0xFF00B283,0xFF00B183,0xFF00B083,0xFF00AF82,0xFF00AE82,0xFF00AE81,0xFF00AC81,0xFF00AB81,0xFF00AA80,0xFF00A980,0xFF00A77F,0xFF00A67F,0xFF00A57E,0xFF00A47E,0xFF00A37D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009C7A,0xFF009A7A,0xFF009979,0xFF009879,0xFF009678,0xFF009477,0xFF009377
  !dd 0xFF009377,0xFF009477,0xFF009578,0xFF009778,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7A,0xFF009E7B,0xFF009F7C,0xFF00A07C,0xFF00A27D,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A87F,0xFF00A980,0xFF00AA80,0xFF00AB81,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00AF82,0xFF00B082,0xFF00B183,0xFF00B183,0xFF00B283,0xFF00B283,0xFF00B383,0xFF00B384,0xFF00B384,0xFF00B384,0xFF00B384,0xFF00B383,0xFF00B283,0xFF00B283,0xFF00B183,0xFF00B183,0xFF00B082,0xFF00AF82,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AB81,0xFF00AA80,0xFF00A980,0xFF00A87F,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A27D,0xFF00A07C,0xFF009F7C,0xFF009E7B,0xFF009C7A,0xFF009B7A,0xFF009979,0xFF009879,0xFF009778,0xFF009578,0xFF009477,0xFF009377
  !dd 0xFF009276,0xFF009377,0xFF009477,0xFF009678,0xFF009879,0xFF009979,0xFF009A7A,0xFF009B7A,0xFF009D7B,0xFF009E7B,0xFF00A07C,0xFF00A17C,0xFF00A27D,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A87F,0xFF00A980,0xFF00AA80,0xFF00AB80,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00AE82,0xFF00AF82,0xFF00B082,0xFF00B083,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B183,0xFF00B083,0xFF00B082,0xFF00AF82,0xFF00AE82,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AB80,0xFF00AA80,0xFF00A980,0xFF00A87F,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A27D,0xFF00A17C,0xFF00A07C,0xFF009E7B,0xFF009D7B,0xFF009B7A,0xFF009A7A,0xFF009979,0xFF009879,0xFF009678,0xFF009477,0xFF009377,0xFF009276
  !dd 0xFF009176,0xFF009377,0xFF009477,0xFF009578,0xFF009778,0xFF009879,0xFF009979,0xFF009B7A,0xFF009C7A,0xFF009D7B,0xFF009F7B,0xFF00A07C,0xFF00A17C,0xFF00A27D,0xFF00A37D,0xFF00A47E,0xFF00A67E,0xFF00A77F,0xFF00A87F,0xFF00A980,0xFF00AA80,0xFF00AB80,0xFF00AC81,0xFF00AC81,0xFF00AD81,0xFF00AE82,0xFF00AE82,0xFF00AF82,0xFF00AF82,0xFF00AF82,0xFF00B082,0xFF00B082,0xFF00B082,0xFF00B082,0xFF00AF82,0xFF00AF82,0xFF00AF82,0xFF00AE82,0xFF00AE82,0xFF00AD81,0xFF00AC81,0xFF00AC81,0xFF00AB80,0xFF00AA80,0xFF00A980,0xFF00A87F,0xFF00A77F,0xFF00A67E,0xFF00A47E,0xFF00A37D,0xFF00A27D,0xFF00A17C,0xFF00A07C,0xFF009F7B,0xFF009D7B,0xFF009C7A,0xFF009B7A,0xFF009979,0xFF009879,0xFF009778,0xFF009578,0xFF009477,0xFF009377,0xFF009176 
EndProcedure

Procedure.i Chip8RenderSprite(*chip8dib.CHIP8DIB,*Sprite.Ascii,X.i,Y.i,Width.i,Height.i)
  Protected px.i
  Protected py.i
  Protected pw.i
  Protected ph.i
  pw = (X + Width) - 1
  ph = (Y + Height) - 1
  For py = Y To ph
    For px = X To pw
      If *Sprite\a
        *chip8dib\PixelTest(px,py)
      EndIf
      *Sprite + 1
    Next
  Next
  ProcedureReturn #Null
EndProcedure

Procedure.i Chip8(Title.s = #Null$,Width.i = 800,Height.i = 400)
  Protected wnd.i
  Protected wnd_flags.i
  Protected wnd_event.i
  Protected wnd_exit.i
  Protected timer_start.i
  Protected timer_stop.i
  Protected *chip8dib.CHIP8DIB
  Protected mov.f
  
  wnd_flags = #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
  wnd = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,wnd_flags) 
  If wnd
    WindowBounds(wnd,Width,Height,#PB_Ignore,#PB_Ignore)
    SetWindowColor(wnd,0)
    *chip8dib = chip8CreateDIB(WindowID(wnd))
    If *chip8dib
      ;*chip8dib\Color($000000,1,0)
      ;*chip8dib\Color($FFFFFF,1,1)
      ;Chip8UploadPalette(*chip8dib,0)
      Repeat
        Repeat
          wnd_event = WindowEvent()
          Select wnd_event
            Case #PB_Event_SizeWindow
              *chip8dib\Resize();auto adjust size + keep aspect ratio
            Case  #PB_Event_CloseWindow 
              wnd_exit = #True
          EndSelect
        Until wnd_event = #Null
        *chip8dib\Clear()
        mov + 0.25
        If mov > 70
          mov = 0
        EndIf
        Chip8RenderSprite(*chip8dib,?sprite0,Cos(mov) + mov - 8,Sin(mov + 5) + 20,5,5)
        Chip8RenderSprite(*chip8dib,?sprite1,Cos(mov) + mov,Sin(mov) + 20,5,5)
        Chip8RenderSprite(*chip8dib,?sprite2,48 - (Cos(mov) + mov),4,25,10)
        *chip8dib\Blit()
        *chip8dib\Clock()
      Until wnd_exit
      *chip8dib\Release()
    EndIf
    CloseWindow(wnd)
  EndIf
  ProcedureReturn #Null
EndProcedure

Chip8()

End

DataSection
  sprite0:
  !db 1,1,1,1,0
  !db 1,0,0,0,1
  !db 1,1,1,1,0
  !db 1,0,0,0,0
  !db 1,0,0,0,0
  sprite1:
  !db 1,1,1,1,0
  !db 1,0,0,0,1
  !db 1,1,1,1,0
  !db 1,0,0,0,1
  !db 1,1,1,1,0
  sprite2:
  !db 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,1,1,1,0,0
  !db 1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,0,0,0,1,0
  !db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0
  !db 0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,1,1,0,1,0,0,0,0,1,0
  !db 0,1,0,0,0,0,1,1,1,1,0,1,0,1,0,0,1,0,0,1,1,1,1,0,0
  !db 0,1,0,0,0,0,1,0,0,1,0,1,0,1,1,1,1,0,1,0,0,0,0,1,0
  !db 0,1,1,1,1,0,1,0,0,1,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0
  !db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0
  !db 1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,0,0,0,1,0
  !db 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,1,1,1,0,0
EndDataSection
Download (chip8dib.lib Version 1.2):
https://www.dropbox.com/s/8u0lwtnv6dvdr ... 2.zip?dl=0

Viel Spass beim Experimentieren :)
Zuletzt geändert von Mijikai am 06.03.2020 21:10, insgesamt 4-mal geändert.
Benutzeravatar
Mijikai
Beiträge: 754
Registriert: 25.09.2016 01:42

Re: [LIB] Chip8 Renderer [Windows x64]

Beitrag von Mijikai »

Update v.1.3 (Windows x64 only!):
- eigener Farbspeicher für jedes Interface (vorher gab es nur einen Globalen Speicher)
- neue Funktion ColorReset() / alle Farbänderungen werden zurückgesetzt

So sieht das neue Interface aus:

Code: Alles auswählen

Interface CHIP8DIB
  Clear.i();clear the backbuffer
  Pixel.i(X.i,Y.i);draws a pixel to the backbuffer using the palette color or single color set
  PixelTest.i(X.i,Y.i);also draws a pixel but checks the boundaries!
  PixelColor.i(X.i,Y.i,Color.i);draws a pixel using the color selected
  PixelColorTest.i(X.i,Y.i,Color.i)
  Blit.i();flips the buffers
  Color.i(Color.i,Type.i = #Null,Flag.i = #Null);color = color value or pointer to palette / if type = 0 -> upload palette if type = 1 -> set color / flag = 0 back- flag = 1 foreground
  ColorReset.i()
  Resize.i();autmatically adjust the ouput to the host size - gadget or window!
  Clock.i()
  Release.i();release all resources
EndInterface
Download:
https://www.dropbox.com/s/5lx41yz04fhns ... 3.zip?dl=0
Zuletzt geändert von Mijikai am 07.03.2020 12:00, insgesamt 1-mal geändert.
Benutzeravatar
Mijikai
Beiträge: 754
Registriert: 25.09.2016 01:42

Re: [LIB] Chip8 Renderer [Windows x64]

Beitrag von Mijikai »

Update v.1.4 (Windows x64 only!):
- neues Interface & neue Funktionen
- umbenennung der Library!

Was damit machbar ist (Palette-Color Manipulation):
Bild

Neues Interface:

Code: Alles auswählen

Import "chip8surface.lib";v.1.4
  chip8CreateSurface.i(hwnd.i)
EndImport

Interface CHIP8_SURFACE
  PixelClear.i()                                    ;clears the screen / fills the backbuffer with palette 0
  Pixel.i(X.i,Y.i)                                  ;draws a pixel at pos xy using the xy color of palette 1
  PixelEx.i(X.i,Y.i)                                ;same as the function above but with boundary checks
  PixelSetColor.i(X.i,Y.i,Color.i)                  ;draws a pixel at pos xy using the provided color
  PixelSetColorEx.i(X.i,Y.i,Color.i)                ;same as the function above but with boundary checks
  PixelGetColor.i(X.i,Y.i)                          ;get the color at pos xy
  PixelGetColorEx.i(X.i,Y.i)                        ;same as the function above but with boundary checks
  PixelBlit.i()                                     ;flips the buffer / render all drawn pixels
  PixelResize.i()                                   ;scales the render surface while keeping the aspect ratio
  PaletteUpdate.i(Index.i,Color.i,Flag.i)           ;upload custom palette (Index 0 / 1) if flag = 0 color is a palette pointer else a fill color!   
  PaletteSetColor.i(Index.i,X.i,Y.i,Color.i)        ;sets a color at pos xy in the selected palette
  PaletteSetColorEx.i(Index.i,X.i,Y.i,Color.i)      ;same as the function above but with boundary checks
  PaletteGetColor.i(Index.i,X.i,Y.i)                ;gets the color stored at pos xy in the selected palette
  PaletteGetColorEx.i(Index.i,X.i,Y.i)              ;same as the function above but with boundary checks
  PaletteReset.i()                                  ;resets palette 0 and 1
  Clock.i()                                         ;a 16 ms timer useful for rendering or emulating the cpu clock of chip8
  Release.i()                                       ;free all resources
EndInterface
Download:
https://www.dropbox.com/s/ye36jej15uab5 ... 4.zip?dl=0

Viel Spass :)
Zuletzt geändert von Mijikai am 07.03.2020 12:00, insgesamt 1-mal geändert.
Benutzeravatar
HeX0R
Beiträge: 2960
Registriert: 10.09.2004 09:59
Computerausstattung: AMD Ryzen 7 5800X
96Gig Ram
NVIDIA GEFORCE RTX 3060TI/8Gig
Win10 64Bit
G19 Tastatur
2x 24" + 1x27" Monitore
Glorious O Wireless Maus
PB 3.x-PB 6.x
Oculus Quest 2
Kontaktdaten:

Re: [LIB] Chip8 Renderer [Windows x64]

Beitrag von HeX0R »

Du solltest ein Beispiel mitliefern, sonst wird sich das sicherlich niemand anschauen.
Habe mir jetzt einen abgebrochen den Beispielcode oben, für die neue Version umzuschreiben.

Es sollte auch erwähnt werden, dass das nur für 64bit ist.

Eine etwas merkwürdige Präsentation Deiner Arbeit, um es mal freundlich zu formulieren.
Ich dachte eigentlich, das wäre ein cooles Gimmick für Eastereggs, aber scheint doch eher was für Freaks zu sein.
Benutzeravatar
Mijikai
Beiträge: 754
Registriert: 25.09.2016 01:42

Re: [LIB] Chip8 Renderer [Windows x64]

Beitrag von Mijikai »

HeX0R hat geschrieben:Du solltest ein Beispiel mitliefern, sonst wird sich das sicherlich niemand anschauen.
Habe mir jetzt einen abgebrochen den Beispielcode oben, für die neue Version umzuschreiben.

Es sollte auch erwähnt werden, dass das nur für 64bit ist.

Eine etwas merkwürdige Präsentation Deiner Arbeit, um es mal freundlich zu formulieren.
Ich dachte eigentlich, das wäre ein cooles Gimmick für Eastereggs, aber scheint doch eher was für Freaks zu sein.
Hallo Hexor :)
danke fürs Feedback.
Für die aktuelle Version gibt es jetzt Beispiele.
Das es nur für Windows x64 ist stand in der Thread Überschrift aber nicht im Update Post werde die Info noch hinzufügen.

Update v.1.5 (Windows x64 only!):
- neue Funktion PixelBlitEx()

Beispiele:

Code: Alles auswählen

;CHIP8_SURFACE - A SMALL (DIB) RENDERER
;AUTHOR: MIJIKAI
;VERSION: 1.5
;OS: WINDOWS X64

EnableExplicit

CompilerIf #PB_Compiler_Processor <> #PB_Processor_x64
   CompilerError "Please use the x64 compiler!"
CompilerEndIf

Import "chip8surface.lib";v.1.5
  chip8CreateSurface.i(hwnd.i)
EndImport

Interface CHIP8_SURFACE
  PixelClear.i()                                    ;clears the screen / fills the backbuffer with palette 0
  Pixel.i(X.i,Y.i)                                  ;draws a pixel at pos xy using the xy color of palette 1
  PixelEx.i(X.i,Y.i)                                ;same as the function above but with boundary checks
  PixelSetColor.i(X.i,Y.i,Color.i)                  ;draws a pixel at pos xy using the provided color
  PixelSetColorEx.i(X.i,Y.i,Color.i)                ;same as the function above but with boundary checks
  PixelGetColor.i(X.i,Y.i)                          ;get the color at pos xy
  PixelGetColorEx.i(X.i,Y.i)                        ;same as the function above but with boundary checks
  PixelBlit.i()                                     ;flips the buffer / renders all drawn pixels
  PixelBlitEx.i(X.i,Y.i,Width.i,Height.i)           ;flips the buffer / only renders the set sub section of drawn pixels
  PixelResize.i()                                   ;scales the render surface while keeping the aspect ratio
  PaletteUpdate.i(Index.i,Color.i,Flag.i)           ;upload custom palette (Index 0 / 1) if flag = 0 color is a palette pointer else a fill color!   
  PaletteSetColor.i(Index.i,X.i,Y.i,Color.i)        ;sets a color at pos xy in the selected palette
  PaletteSetColorEx.i(Index.i,X.i,Y.i,Color.i)      ;same as the function above but with boundary checks
  PaletteGetColor.i(Index.i,X.i,Y.i)                ;gets the color stored at pos xy in the selected palette
  PaletteGetColorEx.i(Index.i,X.i,Y.i)              ;same as the function above but with boundary checks
  PaletteReset.i()                                  ;resets palette 0 and 1
  Clock.i()                                         ;a 16 ms timer useful for rendering / or emulating the cpu clock of chip8
  Release.i()                                       ;free all resources
EndInterface

Procedure.i DemoInitialisation(Title.s = #Null$,Width.i = 600,Height.i = 300);initialisation & clearing the backbuffer
  Protected wnd.i
  Protected wnd_flags.i
  Protected wnd_event.i
  Protected wnd_exit.i
  Protected *surface.CHIP8_SURFACE
  wnd_flags = #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
  wnd = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,wnd_flags) 
  If wnd
    WindowBounds(wnd,Width,Height,#PB_Ignore,#PB_Ignore)
    *surface = chip8CreateSurface(WindowID(wnd));create a render surface
    If *surface
      Repeat
        Repeat
          wnd_event = WindowEvent()
          Select wnd_event
            Case #PB_Event_SizeWindow
              *surface\PixelResize();auto adjust size + keep aspect ratio
            Case #PB_Event_CloseWindow 
              wnd_exit = #True
          EndSelect
        Until wnd_event = #Null
        *surface\PixelClear();clears the screen / fills the backbuffer with palette 0
        *surface\PixelBlit() ;flips the buffer / renders all drawn pixels
        *surface\Clock();a 16 ms timer useful for rendering / or emulating the cpu clock of chip8
      Until wnd_exit
      *surface\Release();release all resources
    EndIf
    CloseWindow(wnd)
  EndIf
  ProcedureReturn #Null
EndProcedure

Procedure.i DemoPixel(Title.s = #Null$,Width.i = 600,Height.i = 300);drawing a pixel
  Protected wnd.i
  Protected wnd_flags.i
  Protected wnd_event.i
  Protected wnd_exit.i
  Protected *surface.CHIP8_SURFACE
  wnd_flags = #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
  wnd = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,wnd_flags) 
  If wnd
    WindowBounds(wnd,Width,Height,#PB_Ignore,#PB_Ignore)
    *surface = chip8CreateSurface(WindowID(wnd))
    If *surface
      Repeat
        Repeat
          wnd_event = WindowEvent()
          Select wnd_event
            Case #PB_Event_SizeWindow
              *surface\PixelResize()
            Case #PB_Event_CloseWindow 
              wnd_exit = #True
          EndSelect
        Until wnd_event = #Null
        *surface\PixelClear()
        *surface\Pixel(1,1);draws a pixel at pos xy using the xy color of palette 1 
        *surface\PixelEx(4,1);same as the function above but with boundary checks (is the pixel inside the 64 x 32 surface)
        *surface\PixelSetColor(1,4,$FF00FF);draws a pixel at pos xy using the provided color (pink in this example)
        *surface\PixelSetColorEx(4,4,$00FF00);same as the function above but with boundary checks
        Debug "Color @ 1 x 4: " + RSet(Hex(*surface\PixelGetColor(1,4)),6,"0");get the color at pos xy - PixelGetColor does th same but with boundary checks
        *surface\PixelBlit()
        *surface\Clock()
      Until wnd_exit
      *surface\Release()
    EndIf
    CloseWindow(wnd)
  EndIf
  ProcedureReturn #Null
EndProcedure

Procedure.i DemoPalette(Title.s = #Null$,Width.i = 600,Height.i = 300);manipulating the palette!
  Protected wnd.i
  Protected wnd_flags.i
  Protected wnd_event.i
  Protected wnd_exit.i
  Protected *surface.CHIP8_SURFACE
  wnd_flags = #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
  wnd = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,wnd_flags) 
  If wnd
    WindowBounds(wnd,Width,Height,#PB_Ignore,#PB_Ignore)
    *surface = chip8CreateSurface(WindowID(wnd))
    If *surface
      ;Index parameter:
      ;0 = palette background
      ;1 = palette foreground (pixles)
      ;Color parameter:
      ;if the Flag parameter is 0: Color is a pointer to a color palette with 64 * 32 colors ($2000 bytes)
      ;if the Flag parameter is 1: Color is infact just a color - this will set the whole internal palette to that one color!
      *surface\PaletteUpdate(0,$000000,1);<- lets make the background palette black!
      *surface\PaletteUpdate(1,$FF00FF,1);<- and the foreground palette pink!
      *surface\PaletteSetColor(0,1,1,$00FF00);<- only change one color in the selected palette (the example makes the entry xy green)!
      Debug "Palette Color @ 1x1: " + RSet(Hex(*surface\PaletteGetColor(0,1,1)),6,"0");<- what color is stored at palette position xy 
      ;*surface\PaletteReset();<- resets palette 1 & 0
      Repeat
        Repeat
          wnd_event = WindowEvent()
          Select wnd_event
            Case #PB_Event_SizeWindow
              *surface\PixelResize()
            Case #PB_Event_CloseWindow 
              wnd_exit = #True
          EndSelect
        Until wnd_event = #Null
        *surface\PixelClear()
        *surface\Pixel(10,10);draw a pixel using the forground palette color!
        *surface\PixelBlit()
        *surface\Clock()
      Until wnd_exit
      *surface\Release()
    EndIf
    CloseWindow(wnd)
  EndIf
  ProcedureReturn #Null
EndProcedure

Procedure.i DemoGadget(Title.s = #Null$,Width.i = 600,Height.i = 300);render into one or more gadget/s!
  Protected wnd.i
  Protected wnd_flags.i
  Protected wnd_event.i
  Protected wnd_exit.i
  Protected *s1.CHIP8_SURFACE
  Protected *s2.CHIP8_SURFACE
  Protected gadget_canvas.i
  Protected gadget_image.i
  wnd_flags = #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
  wnd = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,wnd_flags) 
  If wnd
    WindowBounds(wnd,Width,Height,#PB_Ignore,#PB_Ignore)
    gadget_canvas = CanvasGadget(#PB_Any,220,10,200,100)
    gadget_image = ImageGadget(#PB_Any,10,10,200,100,#Null)
    If gadget_canvas And gadget_image
      *s1 = chip8CreateSurface(GadgetID(gadget_canvas))
      *s2 = chip8CreateSurface(GadgetID(gadget_image))
      If *s1
        If *s2
          *s1\PaletteUpdate(0,$FF00FF,1)
          *s2\PaletteUpdate(0,$00FF00,1)
          Repeat
            Repeat
              wnd_event = WindowEvent()
              Select wnd_event
                Case #PB_Event_SizeWindow
                  ResizeGadget(gadget_canvas,#PB_Ignore,#PB_Ignore,WindowWidth(wnd) - 380,WindowHeight(wnd) - 190)
                  *s1\PixelResize();only resize the gadget canvas_surface
                Case #PB_Event_CloseWindow 
                  wnd_exit = #True
              EndSelect
            Until wnd_event = #Null
            ;--------------
            *s1\PixelClear()
            *s1\PixelBlit()
            ;--------------
            *s2\PixelClear()
            *s2\PixelBlit()
            ;--------------
            *s1\Clock();<- we only need 1 render clock!
          Until wnd_exit
          *s2\Release()
        EndIf
        *s1\Release()
      EndIf
    EndIf
    CloseWindow(wnd)
  EndIf
  ProcedureReturn #Null
EndProcedure

DemoInitialisation("Demo Initialisation")

DemoPixel("Demo Pixel Functions")

DemoPalette("Demo Palette Functions")

DemoGadget("Demo Render into Gadgets")

;PixelBlitEx instead of PixelBlit allows you to render (& scale) a defined area instead of all 64 x 32 pixels!
;-> PixelBlitEx(5,5,20,20) would render 20 x 20 pixels starting from backbuffer position 5 x 5!

End

Download:
https://www.dropbox.com/s/lzdbjjge9juop ... 5.zip?dl=0
Zuletzt geändert von Mijikai am 07.03.2020 16:29, insgesamt 3-mal geändert.
Benutzeravatar
HeX0R
Beiträge: 2960
Registriert: 10.09.2004 09:59
Computerausstattung: AMD Ryzen 7 5800X
96Gig Ram
NVIDIA GEFORCE RTX 3060TI/8Gig
Win10 64Bit
G19 Tastatur
2x 24" + 1x27" Monitore
Glorious O Wireless Maus
PB 3.x-PB 6.x
Oculus Quest 2
Kontaktdaten:

Re: [LIB] Chip8 Renderer [Windows x64]

Beitrag von HeX0R »

O.k., das mit dem x64 habe ich offensichtlich übersehen, tut mir Leid.
Vielleicht solltest Du sowas noch im Beispiel integrieren:

Code: Alles auswählen

CompilerIf #PB_Compiler_Processor <> #PB_Processor_x64
	CompilerError "Please use x64 compiler!"
CompilerEndIf
Danke auf jeden Fall für das Beispiel, ist zwar nicht mehr so "fancy" wie das erste, dafür macht es die Handhabung jetzt selbst für Deppen wie mich klar :allright:

Eine x86 Version ist nicht geplant?
I.d.R. biete ich meine Apps in beiden Versionen an, das würde die Easteregg Möglichkeiten natürlich einschränken.
Benutzeravatar
Mijikai
Beiträge: 754
Registriert: 25.09.2016 01:42

Re: [LIB] Chip8 Renderer [Windows x64]

Beitrag von Mijikai »

HeX0R hat geschrieben: Vielleicht solltest Du sowas noch im Beispiel integrieren:

Code: Alles auswählen

CompilerIf #PB_Compiler_Processor <> #PB_Processor_x64
	CompilerError "Please use x64 compiler!"
CompilerEndIf
Habs hinzugefügt und die die Dateien neu hochgeladen :)
HeX0R hat geschrieben: Eine x86 Version ist nicht geplant?
I.d.R. biete ich meine Apps in beiden Versionen an, das würde die Easteregg Möglichkeiten natürlich einschränken.
Momentan nicht.
Benutzeravatar
Mijikai
Beiträge: 754
Registriert: 25.09.2016 01:42

Re: [LIB] Chip8 Renderer [Windows x64]

Beitrag von Mijikai »

PONG Demo :)

Image:
Bild

Code:

Code: Alles auswählen

;CHIP8_SURFACE - A SMALL DIB RENDERER FOR CHIP8 PROJECT
;AUTHOR: MIJIKAI
;VERSION: 1.5

EnableExplicit

Import "chip8surface.lib";v.1.5
  chip8CreateSurface.i(hwnd.i)
EndImport

Interface CHIP8_SURFACE
  PixelClear.i()                                    ;clears the screen / fills the backbuffer with palette 0
  Pixel.i(X.i,Y.i)                                  ;draws a pixel at pos xy using the xy color of palette 1
  PixelEx.i(X.i,Y.i)                                ;same as the function above but with boundary checks
  PixelSetColor.i(X.i,Y.i,Color.i)                  ;draws a pixel at pos xy using the provided color
  PixelSetColorEx.i(X.i,Y.i,Color.i)                ;same as the function above but with boundary checks
  PixelGetColor.i(X.i,Y.i)                          ;get the color at pos xy
  PixelGetColorEx.i(X.i,Y.i)                        ;same as the function above but with boundary checks
  PixelBlit.i()                                     ;flips the buffer / render all drawn pixels
  PixelBlitEx.i(X.i,Y.i,Width.i,Height.i)           ;flips the buffer / only renders the set sub section of drawn pixels
  PixelResize.i()                                   ;scales the render surface while keeping the aspect ratio
  PaletteUpdate.i(Index.i,Color.i,Flag.i)           ;upload custom palette (Index 0 / 1) if flag = 0 color is a palette pointer else a fill color!   
  PaletteSetColor.i(Index.i,X.i,Y.i,Color.i)        ;sets a color at pos xy in the selected palette
  PaletteSetColorEx.i(Index.i,X.i,Y.i,Color.i)      ;same as the function above but with boundary checks
  PaletteGetColor.i(Index.i,X.i,Y.i)                ;gets the color stored at pos xy in the selected palette
  PaletteGetColorEx.i(Index.i,X.i,Y.i)              ;same as the function above but with boundary checks
  PaletteReset.i()                                  ;resets palette 0 and 1
  Clock.i()                                         ;a 16 ms timer useful for rendering / or emulating the cpu clock of chip8
  Release.i()                                       ;free all resources
EndInterface

Structure PONG_POSITION
  x.f
  y.f
EndStructure

Structure PONG_BALL
  pos.PONG_POSITION
  dir.PONG_POSITION
  vel.PONG_POSITION
  mod.PONG_POSITION[28] 
EndStructure

Structure PONG_PADDLE
  pos.PONG_POSITION
EndStructure

Structure PONG
  ball.PONG_BALL
  paddle.PONG_PADDLE[2]
  key.i[4]
EndStructure

Procedure.i PongInit(*pong.PONG)
  *pong\ball\pos\x = 31
  *pong\ball\pos\y = Random(16,15)
  Repeat
    *pong\ball\dir\x = -1 + Random(2)
    *pong\ball\dir\y = -1 + Random(2)
  Until *pong\ball\dir\x <> 0 And *pong\ball\dir\y <> 0
  *pong\ball\vel\x = 1
  *pong\ball\vel\y = 0.1
  *pong\paddle[0]\pos\x = 2
  *pong\paddle[0]\pos\y = 12
  *pong\paddle[1]\pos\x = 61
  *pong\paddle[1]\pos\y = 12
  FillMemory(@*pong\ball\mod[0],28,-1082130432,#PB_Long)
  ProcedureReturn #Null
EndProcedure

Procedure.i PongUpdate(*surface.CHIP8_SURFACE,*pong.PONG)
  Protected index.i
  Protected color.i
  Protected drift.f
  ;-----------------------------------------------
  *pong\paddle[0]\pos\y - *pong\key[0]
  *pong\paddle[0]\pos\y + *pong\key[1]
  If *pong\paddle[0]\pos\y < 0
    *pong\paddle[0]\pos\y = 0
  ElseIf *pong\paddle[0]\pos\y > 24
    *pong\paddle[0]\pos\y = 24
  EndIf
  *pong\paddle[1]\pos\y - *pong\key[2]
  *pong\paddle[1]\pos\y + *pong\key[3]
  If *pong\paddle[1]\pos\y < 0
    *pong\paddle[1]\pos\y = 0
  ElseIf *pong\paddle[1]\pos\y > 24
    *pong\paddle[1]\pos\y = 24
  EndIf
  ;-----------------------------------------------
  CopyMemory(@*pong\ball\mod[0],@*pong\ball\mod[1],216)
  *pong\ball\pos\x + (*pong\ball\dir\x * *pong\ball\vel\x)
  *pong\ball\pos\y + (*pong\ball\dir\y * *pong\ball\vel\y)
  ;-----------------------------------------------
  If *pong\ball\pos\x > *pong\paddle[0]\pos\x - 0.1 And *pong\ball\pos\x < *pong\paddle[0]\pos\x + 0.1
    If *pong\ball\pos\y > (*pong\paddle[0]\pos\y - 1) And *pong\ball\pos\y < (*pong\paddle[0]\pos\y + 7.1)
      *pong\ball\dir\x * -1
      drift = Abs(*pong\paddle[0]\pos\y - *pong\ball\pos\y + 3)
    EndIf
  EndIf
  ;-----------------------------------------------
  If *pong\ball\pos\x > *pong\paddle[1]\pos\x - 0.1 And *pong\ball\pos\x < *pong\paddle[1]\pos\x + 0.1
    If *pong\ball\pos\y > (*pong\paddle[1]\pos\y - 0.1) And *pong\ball\pos\y < (*pong\paddle[1]\pos\y + 7.1)
      *pong\ball\dir\x * -1
       drift = Abs(*pong\paddle[1]\pos\y - *pong\ball\pos\y + 3)
    EndIf
  EndIf
  ;-----------------------------------------------
  If drift
    drift / 4
    If drift < 0.1
      drift + 0.1 + (Random(3) / 10)
    EndIf
    *pong\ball\vel\y = drift
  EndIf
  ;-----------------------------------------------
  If *pong\ball\pos\x < 0 
    ;*pong\ball\pos\x = 0
    ;*pong\ball\dir\x * -1 
    PongInit(*pong)
  ElseIf *pong\ball\pos\x > 63
    ;*pong\ball\pos\x = 63
    ;*pong\ball\dir\x * -1 
    PongInit(*pong)
  EndIf
  ;-----------------------------------------------
  If *pong\ball\pos\y < 0
    *pong\ball\pos\y = 0
    *pong\ball\dir\y * -1
  ElseIf *pong\ball\pos\y > 31
    *pong\ball\pos\y = 31
    *pong\ball\dir\y * -1 
  EndIf
  ;-----------------------------------------------
  *pong\ball\mod[0]\x = *pong\ball\pos\x
  *pong\ball\mod[0]\y = *pong\ball\pos\y
  For index = 0 To 27
    If *pong\ball\mod[index]\x = -1
      Break
    EndIf
    color = *surface\PaletteGetColorEx(0,*pong\ball\mod[index]\x,15) + $1000 + index
    *surface\PixelSetColorEx(*pong\ball\mod[index]\x,*pong\ball\mod[index]\y,color)
  Next
  *surface\PixelEx(*pong\ball\pos\x,*pong\ball\pos\y)
  ;-----------------------------------------------
  For index = 0 To 7
    *surface\PixelEx(*pong\paddle[0]\pos\x,*pong\paddle[0]\pos\y + index)
    *surface\PixelEx(*pong\paddle[1]\pos\x,*pong\paddle[1]\pos\y + index)
  Next
  ProcedureReturn #Null
EndProcedure

Procedure.i PongInput(*surface.CHIP8_SURFACE,*pong.PONG)
  Protected wnd_event.i
  Protected wnd_exit.i
  Repeat
    wnd_event = WindowEvent()
    Select wnd_event
      Case #WM_KEYDOWN
        Select EventwParam()
          Case #VK_W
            *pong\key[0] = 1
          Case #VK_S
            *pong\key[1] = 1
          Case #VK_P
            *pong\key[2] = 1
          Case #VK_L
            *pong\key[3] = 1
        EndSelect
      Case #WM_KEYUP
        Select EventwParam()
          Case #VK_W
            *pong\key[0] = 0
          Case #VK_S
            *pong\key[1] = 0
          Case #VK_P
            *pong\key[2] = 0
          Case #VK_L
            *pong\key[3] = 0
        EndSelect
      Case #PB_Event_SizeWindow
        *surface\PixelResize()
      Case #PB_Event_CloseWindow 
        wnd_exit = 1
    EndSelect
  Until wnd_event = #Null
  ProcedureReturn wnd_exit
EndProcedure

Procedure.i PongSprite(*surface.CHIP8_SURFACE,*Sprite.Ascii,X.i,Y.i,Width.i,Height.i,Color.i)
  Protected px.i
  Protected py.i
  Protected pw.i
  Protected ph.i
  pw = (X + Width) - 1
  ph = (Y + Height) - 1
  For py = Y To ph
    For px = X To pw
      If *Sprite\a
        If Color = 0
          *surface\PixelEx(px,py)
        Else
          *surface\PixelSetColorEx(px,py,Color)
        EndIf
      EndIf
      *Sprite + 1
    Next
  Next
  ProcedureReturn #Null
EndProcedure

Procedure.i Demo(Title.s = #Null$,Width.i = 600,Height.i = 400)
  Protected wnd.i
  Protected wnd_flags.i
  Protected wnd_event.i
  Protected wnd_exit.i
  Protected *surface.CHIP8_SURFACE
  Protected mov.f
  Protected game.PONG
  Protected color1.i
  Protected color2.i
  wnd_flags = #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
  wnd = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,wnd_flags) 
  If wnd
    WindowBounds(wnd,Width,Height,#PB_Ignore,#PB_Ignore)
    SetWindowColor(wnd,0)
    *surface = chip8CreateSurface(WindowID(wnd))
    If *surface
      PongInit(@game)
      color1 = *surface\PaletteGetColorEx(0,0,0)
      Repeat
        If PongInput(*surface,@game)
          Break  
        EndIf       
        *surface\PixelClear() 
        color2 = *surface\PaletteGetColorEx(0,game\ball\pos\x,game\ball\pos\y)
        If color2 = 0
          color2 = color1
        EndIf
        PongSprite(*surface,?sprite,22,13,20,6,color2)
        PongUpdate(*surface,@game)
        *surface\PixelBlit()
        *surface\Clock()
      Until wnd_exit
      *surface\Release()
    EndIf
    CloseWindow(wnd)
  EndIf
  ProcedureReturn #Null
EndProcedure

;PONG DEMO

;CONTROLS:
;-> LEFT  PADDLE: [KEY W] = UP / [KEY S] = DOWN 
;-> RIGHT PADDLE: [KEY P] = UP / [KEY L] = DOWN 

Demo("PONG")

End

DataSection
  sprite:
  !db 1,1,1,0,0,0,1,1,0,0,1,0,0,1,0,0,1,1,1,0
  !db 1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,0
  !db 1,0,0,1,0,1,0,0,1,0,1,1,0,1,0,1,0,0,0,0
  !db 1,1,1,0,0,1,0,0,1,0,1,0,1,1,0,1,0,1,1,0
  !db 1,0,0,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0
  !db 1,0,0,0,0,0,1,1,0,0,1,0,0,1,0,0,1,1,0,1
EndDataSection
Benutzeravatar
Mijikai
Beiträge: 754
Registriert: 25.09.2016 01:42

Re: [LIB] Chip8 Renderer [Windows x64]

Beitrag von Mijikai »

Break Out Demo

Image:
Bild

Code:

Code: Alles auswählen

EnableExplicit

;BreakOut Demo Thing
;Author: Mijikai

Import "chip8surface.lib";v.1.5 -> https://www.purebasic.fr/german/viewtopic.php?p=356246#p356246
  chip8CreateSurface.i(hwnd.i)
EndImport

Interface CHIP8_SURFACE
  PixelClear.i()                                    ;clears the screen / fills the backbuffer with palette 0
  Pixel.i(X.i,Y.i)                                  ;draws a pixel at pos xy using the xy color of palette 1
  PixelEx.i(X.i,Y.i)                                ;same as the function above but with boundary checks
  PixelSetColor.i(X.i,Y.i,Color.i)                  ;draws a pixel at pos xy using the provided color
  PixelSetColorEx.i(X.i,Y.i,Color.i)                ;same as the function above but with boundary checks
  PixelGetColor.i(X.i,Y.i)                          ;get the color at pos xy
  PixelGetColorEx.i(X.i,Y.i)                        ;same as the function above but with boundary checks
  PixelBlit.i()                                     ;flips the buffer / render all drawn pixels
  PixelBlitEx.i(X.i,Y.i,Width.i,Height.i)           ;flips the buffer / only renders the set sub section of drawn pixels
  PixelResize.i()                                   ;scales the render surface while keeping the aspect ratio
  PaletteUpdate.i(Index.i,Color.i,Flag.i)           ;upload custom palette (Index 0 / 1) if flag = 0 color is a palette pointer else a fill color!   
  PaletteSetColor.i(Index.i,X.i,Y.i,Color.i)        ;sets a color at pos xy in the selected palette
  PaletteSetColorEx.i(Index.i,X.i,Y.i,Color.i)      ;same as the function above but with boundary checks
  PaletteGetColor.i(Index.i,X.i,Y.i)                ;gets the color stored at pos xy in the selected palette
  PaletteGetColorEx.i(Index.i,X.i,Y.i)              ;same as the function above but with boundary checks
  PaletteReset.i()                                  ;resets palette 0 and 1
  Clock.i()                                         ;a 16 ms timer useful for rendering / or emulating the cpu clock of chip8
  Release.i()                                       ;free all resources
EndInterface

Structure GAME_BLOCK_STRUCT
  flag.i
  x.i
  y.i
EndStructure

Structure GAME_BALL_STRUCT
  x.i
  y.i
  dx.i
  dy.i
EndStructure

Structure GAME_PADDLE_STRUCT
  factor.f
  x.i
  y.i
EndStructure

Structure GAME_STRUCT
  paddle.GAME_PADDLE_STRUCT
  ball.GAME_BALL_STRUCT
  block_width.i
  block_height.i
  block.GAME_BLOCK_STRUCT[40]
EndStructure

#GAME_COLOR_PADDLE = $00DC00
#GAME_COLOR_BALL = $00DC00
#GAME_COLOR_BLOCK_1 = $003200
#GAME_COLOR_BLOCK_2 = $000D00

Global *surface.CHIP8_SURFACE
Global game.GAME_STRUCT

Procedure.i GameInit(Window.i)
  Protected px.i
  Protected py.i
  Protected index.i
  ClearStructure(@game,GAME_STRUCT)
  With game
    \paddle\factor = (WindowWidth(Window) / 64)
    \paddle\x = (WindowMouseX(Window) / game\paddle\factor) - 5
    \paddle\y = 29
    \ball\x = 31 - 20
    \ball\y = 27
    \ball\dx = 1
    \ball\dy = -1
    \block_width = 4
    \block_height = 2
    For px = 0 To 9
      For py = 0 To 3
        \block[index]\flag = 1
        \block[index]\x = (px * 6) + 3
        \block[index]\y = (py * 4) + 2
        index + 1
      Next
    Next
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameDrawBlock(X.i,Y.i,Width.i,Height.i,Center.i = #False,Color.i = #Null)
  Protected px.i
  Protected py.i
  If Center
    X - (Width >> 1)
    Y - (Height >> 1)
  EndIf  
  Width = X + Width - 1
  Height = Y + Height - 1
  If Color
    For px = X To Width
      For py = Y To Height
        *surface\PixelSetColor(px,py,Color)
      Next
    Next
  Else
    For px = X To Width
      For py = Y To Height
        *surface\Pixel(px,py)
      Next
    Next
  EndIf
  ProcedureReturn #Null
EndProcedure

Procedure.i GameDrawBlocks()
  Protected index.i
  With game
    For index = 0 To 39
      If \block[index]\flag
        GameDrawBlock(\block[index]\x,\block[index]\y,\block_width,\block_height,#False,#GAME_COLOR_BLOCK_1)
      Else
        GameDrawBlock(\block[index]\x,\block[index]\y,\block_width,\block_height,#False,#GAME_COLOR_BLOCK_2)
      EndIf
    Next
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameCollision(Index.i)
  With game
    If \block[Index]\flag
      If \ball\x > \block[Index]\x And \ball\x < (\block[Index]\x + \block_width)
        If \ball\y > \block[Index]\y And \ball\y < (\block[Index]\y + \block_height)
          If \ball\y = \block[Index]\y
            \ball\dx * -1 
          Else
            \ball\dy * -1
          EndIf
          \block[Index]\flag = 0
        EndIf
      EndIf
    EndIf
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameLogic(Window.i)
  Protected index.i
  With game
    If \paddle\x < 0
      \paddle\x = 0
    ElseIf \paddle\x > 54
      \paddle\x = 54
    EndIf
    \ball\x + \ball\dx
    \ball\y + \ball\dy
    If \ball\y < 0
      \ball\y = 0
      \ball\dy * -1
    ElseIf \ball\y > 31
      \ball\y = 31
      \ball\dy * -1
      GameInit(Window)
    EndIf
    If \ball\x < 0
      \ball\x = 0
      \ball\dx * -1
    ElseIf \ball\x > 63
      \ball\x = 63
      \ball\dx * -1
    EndIf
    If \ball\y = 29
      If \ball\x > \paddle\x And \ball\x < (\paddle\x + 10)
        \ball\dy * -1
      EndIf
    EndIf
    For index = 0 To 39
      GameCollision(index)
    Next
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i GameRender()
  With game
    *surface\PixelClear()
    GameDrawBlocks()
    GameDrawBlock(game\paddle\x,\paddle\y,10,1,#False,#GAME_COLOR_PADDLE)
    *surface\PixelSetColor(\ball\x,\ball\y,#GAME_COLOR_BALL)
    *surface\PixelBlit()
    *surface\Clock()
    ProcedureReturn #Null
  EndWith
EndProcedure

Macro GameUpdate() 
  GameInit(wnd)
  Repeat
    Repeat  
      wnd_event = WindowEvent()
      Select wnd_event
        Case #PB_Event_SizeWindow
          *surface\PixelResize()
          game\paddle\factor = (WindowWidth(wnd) / 64) 
        Case #PB_Event_CloseWindow
          Break 2
      EndSelect
    Until wnd_event = #Null
    game\paddle\x = (WindowMouseX(wnd) / game\paddle\factor) - 5
    GameLogic(wnd)
    GameRender()
  ForEver
  *surface\Release()
EndMacro

Procedure.i Main(Width.i,Height.i,Title.s = #Null$)
  Protected wnd.i
  Protected wnd_flags.i
  Protected wnd_event.i
  wnd_flags = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered
  wnd = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,wnd_flags)
  If wnd
    WindowBounds(wnd,Width,Height,#PB_Ignore,#PB_Ignore)
    SetWindowColor(wnd,$0)
    *surface = chip8CreateSurface(WindowID(wnd))
    If *surface
      GameUpdate() 
    EndIf
    CloseWindow(wnd)
  EndIf
  ProcedureReturn #Null
EndProcedure

Main(800,600,"BreakOut")

End
Antworten