'===========================================================================
' Subject: .NES ROMS IMAGE DISPLAYER          Date: 06-29-99 (12:44)       
'  Author: David A. Wicker                    Code: QB, QBasic, PDS        
'  Origin: topaz817@netzero.net             Packet: MISC.ABC
'===========================================================================
' >> EditNes v0.1 -- Written by David A. Wicker -- topaz817@fastlane.net
' ---------------------------------------------------------------------------
' As always, if you borrow anything from any source code for your
' shareware projects, please give credit to the original author!
' ---------------------------------------------------------------------------

' Yup!  If you have your hot little hands on a .NES file then this program
' is for you!

' If you don't have any .NES files, don't ask me!  There's literally
' thousands for download.  Use your favorite internet search engine to
' locate them.

' [ENTER] or [SPACE] - get next page
'                      Be patient!  Just tap that [ENTER] until something
'                      interesting pops up on the screen, then use your keys
'                      "1" - "6" to make it easier to see for yourself.
' [BACKSPACE] - go back one page
' "-" OR "+" increment or decrement by one character (for use with Quad)
' "Q" enter or leave Quad mode (useful for finding all those images of people
'     in any of the Final Fantasy ROMs
' "[" or "]" increment or decrement by 4 characters (shifting quad by one)

' "1","2","3","4","5","6" change the palette's appearance to locate images
' of people AND stuff.

' These instructions below are for Win98 users.

' So what do you do after you have some images, be it sprites or fonts on
' your screen you are ready to rip for your freeware projects ?
' Well, first off, can you see the word (Start) at the bottom-left hand
' corner of your display, if so, skip this next step.

' Hold down the [ALT] key and lightly tap the [ENTER] once.  Release both.
' click on the picture of the dotted line square at the top of the screen.
' If you don't see this dotted line square, move the mouse pointer so it
' sits on top of the MSDOS icon in the top-left hand corner.  Tap the
' mouse button once and select TOOLBAR.

' There!  Now it should appear!  After clicking on the dotted line square
' a select field will appear, use the right arrow key and go all the way to
' the right, then the down arrow key to go all the way down.

' When you have highlighted the entire screen, click on the picture of
' the clipboard.  There!  You just made a copy of SCREEN 13 to Win98's
' Clipboard!  Bring up your favorite paint program and PASTE it in with
' SHIFT-INSERT.  Naturally you gotta change the colors to what YOU want!

' To get back to full-screen DOS mode (which you should always be in anyways
' for running any of William Yu's nice programs), just hit the ALT-ENTER once
' again.  Enjoy!

DEFINT A-Z
'$DYNAMIC
DECLARE SUB ShutDown ()
DECLARE SUB GetKey ()
DECLARE SUB RGB (N, R, G, B)

CLS
LOCATE 24
INPUT "Name of nintendo rom:", F$
IF F$ = "" THEN END
SHELL "copy " + F$ + ".nes editnes.nes"

DEF FNC$ (A$, A) = MID$(A$, A, 1)
DEF FNCTRL$ (A$) = CHR$(ASC(A$) - 64)

R(0) = 21: G(0) = 42: B(0) = 21
R(1) = 63: G(1) = 50: B(1) = 50
R(2) = 42: G(2) = 21: B(2) = 0

Pat$ = "012 021 102 120 201 210"

SCREEN 13

FOR I = 0 TO 2
  RGB 17 + I, R(I), G(I), B(I)
NEXT

OPEN "r", 1, "editnes.nes", 1
FIELD 1, 1 AS R.C$

Again:
LINE (0, 0)-(319, 199), 0, BF
FOR I = 0 TO 15
  FOR J = 0 TO 31
    FOR M = 0 TO Quad
      FOR N = 0 TO Quad
        X = (J + N) * 8
        Y = (I + M) * 8
        FOR K = 0 TO 7
          N& = N& + 1
          GET 1, N&
          C = ASC(R.C$)
          GET 1, N& + 8&
          C2 = ASC(R.C$)
          Y = Y + 1
          FOR L = 0 TO 7
            XX = 2 ^ (7 - L)
           
            IF C AND XX THEN PSET (X + L, Y), 17
            IF C2 AND XX THEN PSET (X + L, Y), 18
            IF C AND XX AND C2 AND XX THEN PSET (X + L, Y), 19
' >> ^ We're doing some boolean logic and bit-math comparisons here!
'      See if you can see what this does!

          NEXT
        NEXT
        N& = N& + 8
      NEXT
    NEXT
    J = J + Quad
  NEXT
  I = I + Quad
NEXT
EN.1:
GetKey
IF VAL(K$) > 0 AND VAL(K$) < 7 THEN
  V = VAL(K$)
  FOR I = 0 TO 2
    RGB 17 + VAL(FNC$(Pat$, (V - 1) * 4 + I + 1)), R(I), G(I), B(I)
  NEXT
  GOTO EN.1
END IF
IF K$ = "[" THEN N& = N& - 64
IF K$ = "]" THEN N& = N& + 64
IF K$ = "-" THEN N& = N& - 16
IF K$ = "+" THEN N& = N& + 16
IF K$ = "Q" THEN Quad = 1 - Quad
N& = N& - 8192&
IF K$ = " " OR K$ = CHR$(13) THEN N& = N& + 8192
IF K$ = CHR$(8) THEN N& = N& - 8192
GOTO Again

REM $STATIC
SUB GetKey : SHARED K$
  DO
    K$ = UCASE$(INKEY$)
  LOOP UNTIL K$ > ""
  IF K$ = CHR$(27) OR K$ = FNCTRL$("Q") THEN ShutDown
END SUB

SUB RGB (N, R, G, B)
  OUT &H3C8, N
  OUT &H3C9, R
  OUT &H3C9, G
  OUT &H3C9, B
END SUB

SUB ShutDown
  CLOSE
  KILL "editnes.nes"
  SCREEN 0: WIDTH 80
  END
END SUB
