오늘도 역시나 열심히 NDS용 그래픽 라이브러리를 손보다가 문득 지난번에 만들어 놓은 고속 복사 함수를 적용시켜보면 어떨까 하는 생각이 들어서 LDMIA, STMIA 함수를 이용해서 메모리를 전송하는 소스를 넣어봤다.

LCD의 해상도고 256 * 192 이고 한 점이 2Byte로 구성되므로 총 98304 Byte, 즉 96 KByte가 되는데 이것을 memcpy()로 복사하니 대략 7 ~ 8 ms 정도가 걸렸다.

이것을 내가 만든 함수로 교체하니 4 ms 로 줄어들었다. @0@)/~

덕분에 약간의 속도 향상이... ㅜ_ㅜ...

아아~ 아직 죽지 않았어.. ㅜ_ㅜ....

오늘 어찌하다가 집에 가지 못해서... 어제 하던 윈도우 시스템이나 마저 손볼려고 코드를 열었다.

그때가 11시쯤이었던가... 지금이 7시니까 대충 8시간쯤 삽질했네...

뭐 그래도 소득은 있으니까... ㅎㅎ

BitBlt 기능을 DC에 추가해서 윈도우에 스킨 입히는 작업과 NDS에서 사용하기위한 그래픽 포맷(Kkamagui Nds Graphic - KNG)을 대충 만들고 변환해주는 프로그램을 만들었다.

그리고 윈도우가 많아져서 깜빡임이 심해지는 걸 느끼고 내친김에 더블 버퍼링까지...

하드코어로 작업했기 때문에 속도가 그리 빠른 편은 아니지만... 그래도 얼추 쓸만은 하다.

아래는 스크린 샷...

사용자 삽입 이미지


ps) 아까 아는 형이 좀 쉬라고 하던데... 이것도 병이라고... ㅡ_ㅡ;;;

정말 그런듯... 왠지 허접한 기기만 보면 기능 확장하고 싶은 충동이... ㅜ_ㅜ...

프로그래머가 천직인가....

NDS에 쉘을 만들어보려고 고민하던중에, KKAMAGUI Notepad 프로그램을 만들면서 썼던 허접 윈도우 라이브러리를 사용하면 쉽게 개발할 수 있을 듯한 생각이 들었다.

어디까지 구현한지 가물가물해서 소스를 뒤지고 있는데...

얼래... ㅡ_ㅡ;;; 거의 구현 안되어있는 것과 마찬가지....

노트패드 기능 구현한다고 윈도우 껍데기나 겨우 만들어 놓은 상태랄까...

클립핑 처리는 전혀 안되있고.... ㅡ_ㅡ;;;

그래서 일단 클립핑부터 시작했는데, 이게 장난이 아니더라....

구글링해서 찾은 알고리즘은 제대로 동작안해서 또 삽질하고... ㅜ_ㅜ...

우의곡절끝에 겨우 0.1 버전을 완성할 수 있었다.

기능은 클립핑 처리 + 윈도우 Z Order 지원 + 터치스크린을 이용한 윈도우 이동 및 종료 등등이다.

내일은 좀더 손봐서 PNG 파일 포맷을 읽어 표시할 수 있도록 해야겠다.

사용자 삽입 이미지
NDS의 윈도우 라이브러리를 손보려고 코드를 고치다가...

얼래... 잘되던 코드가 안되는 문제를 발견했다.

한참을 디버깅하다가... 코드의 순서를 살짝 바꾸니 이상한 데이터가 덤프되는 것을 발견하고...

Optimazation 할때 스택쪽에 문제가 생기거나 Register를 잘못 사용하고 있는 것이 아닌가 추측...

옵션을 O2에서 O1으로 낮춘 다음 전부 다시 컴파일하여 실행하니....

아무 문제 없이 실행되었다 @0@)/!!!!!

이런... ㅜ_ㅜ... 내 시간 돌려도.. ㅜ_ㅜ
여자친구가 생일선물을 해준다고 하길래 PSP를 중고로 사달라고 할까 고민하다가 이미 NDS를 가지고 있는지라 쓰지 않을 것 같은 생각이 들었다.

그래서 그냥 NDS에 메모리나 더 꼽을까 하고 G 마켓을 뒤졌는데...

어라? 왠 확장팩이 나왔다. 3 in 1 Expansion Pack for EZ-Flash라는 물건인데, 진동 + 메모리 확장 + GBA 팩 기능까지 하는 모양이다.

좀더 확실히 알기위해서 구글 형께 부탁했더니 아래와 같은 사이트를 보여줬다.

http://wiki.gbatemp.net/index.php?title=3_in_1_Expansion_Pack_for_EZ-Flash_V

사용자 삽입 이미지

뭐 진동이나 GBA를 할 수 있다는 그런건 별로 안땡기고... 램을 확장할 수 있는 점이 홈브루를 개발하는 나에게 가장 큰 장점인듯....

과연 얼마나 확장될까? 위의 사이트에 따르면...
  • 256 Mb (32 MB) of NOR Flash Memory. This type of memory is able to retain data without requiring uninterrupted power. Depending on data size, writing may take up to several minutes. One typical use includes copying over a GBA ROM, thereby allowing the 3-in-1 to act like a real GBA cartridge.
  • 128 Mb (16 MB) of PSRAM. This memory does not retain data when the power is turned off. However it can be written at speeds much faster than NOR memory.
  • 4 Mb (512 KB) of battery backed SRAM for save data. The battery is necessary to retain data.
  • Programmable embedded "rumble pak" (haptic feedback) device

무려 16MByte @0@)/~!!!

NDS 자체의 램이 4MByte 정도니까 합이 20MByte @0@)/~!!!!!

두둥... PSP가 32MByte인 것을 감안할 때 굉장한 붐업이다...

ㅜ_ㅜ... 당장 질러서 테스트 프로그램이나 하나 만들어봐야겠다...

다들 기대하시라 ㅎㅎ

>ㅁ<)/~!!!

이럴수가... 다시 재발했다.. @0@)/~

예전보다야 나아졌지만 화면 우측에 필기를 하면 튀는 현상이 생긴다.

이렇게 되면 결국 Z 축(누르는 압력)을 이용해서 계산하는 수 밖에 없는데....

결국 쓰긴 써야하나....


터치 스크린에 어중간한 압력이 들어갔을 때, 엄한 값이 나오는듯 한데...

세게 눌러서 필기를 하면 괜찮은 것 보니....

아우... 머리야... 또 수정해야겠군....
LCD와 Graphic에 관련된 Power는 ARM 9에서도 건드릴 수 있었는데...

전체적인 System의 Power 관리(LED 포함)는 SPI를 이용해서 Power Management Device로 전송해야 한다...

아래는 SPI에 관한 내용... ARM 7을 통해서만 가능...

http://nocash.emubase.de/gbatek.htm#dsserialperipheralinterfacebusspi


아래는 Power Device에 관한 내용...
LED 색깔 바꾸는거, 깜박이는거... Shutdown 하는거 등등 가능...
http://nocash.emubase.de/gbatek.htm#dspowermanagement

시간나면 해봐야 겠다.

basicARM7 코드가 굉장히 간단하게 되어있던데...
소스를 얼핏 보니까 LCD의 HSync Interrupt를 받아서 Touch의 값을 읽도록 되어있었다.
혹시 이것때문에 LCD의 값이 튀는게 아닐까?
Touch의 Interrupt를 받아서 값을 읽으면 더 나을수도.... ㅡ_ㅡa...

일단 생각해 보자...
대단하다... 이미지 돌리기부터 해서 확대... 축소 같은 기능도 구현되어있다.. @0@)/~

이거라면 데이터 시트 같은 것도 NDS에 넣어 다니면서 볼 수 있겠던데....

크윽... 너무 좋은거 아냐.. ㅜ_ㅜ...
크아... libfat Library에 버그를 발견했다.

첫번째 버그는 파일을 열자마자 fseek()로 제일 처음으로 이동한다음, 다시 fseek()로
제일 마지막으로 옮겨간 후, write를 하면 정상적으로 write가 되지 않는 버그이고...

다른 한가지는 파일 끝에서 데이터를 쓰면 파일이 커지긴 하는데 쓰레기 데이터가
채워져서 커지는 버그이다.

일단 이 릴리즈 전버전으로 해서 다시 테스트 해보고 소스를 수정하던지...
아님 짜던지 해야겠다. ㅜ_ㅜ

아놔... 오늘도 하루를 다 날렸네.. ㅜ_ㅜ
invalid-file

파일 다운로드



흐.. 이런... libfat의 버그를 찾다 찾다 결국 그냥 포기...
(사실 귀찮아서 소스 보기를 포기... ㅡ_ㅡ )

버그를 우회하는 식으로 해결했다.
이놈이 글쎄.. fopen으로 r+ 옵션으로 열어서 파일 끝에서 데이터를 추가하면...
이상하게 변한다.... ㅡ_ㅡa.. 캐쉬 정책이랑 실제 flash write하는 기능이
제대로 동작하지 않는거 같기도 하고.... ㅜ_ㅜ...

그래서 파일 끝에서 추가할때는 a+ 옵션을 줘서 일부러 클러스터를 다 따라가게
만들고, 추가없이 파일을 수정만때는 r+ 옵션으로 열어서 바꾸도록 했다.

이렇게 하니 별 이상없이 동작하는구나... ㅜ_ㅜ...

크윽.. 젠장... 나중에 삼성과제 끝나고 나면 그걸 그대로 올려야 겠다.
역시... 내손으로 만드는게 좀더 믿음직 하네...

사용자 삽입 이미지
아우... 메모장 하나 만드는데 왜이렇게 오래 걸리는지... ㅡ_ㅡ;;;

메모장 하나 만들려고 윈도우 구조 다 세우고 Window base Class 만들고 CDC 만들고...
아주 난리다... ㅡ_ㅡa...

왜 이짓을 하는지 의문이긴한데... 어느정도 대충 가다는 나왔다는 ㅎㅎㅎ
이제 조금만 더하면 그림판 같은걸 만들 수 있겠다.

앗싸~ >ㅁ<)/~
libfat를 받아서 내 의사용 microSD io 코드를 추가한 다음
약간의 수정을 거쳐 만든 library 및 소스

테스트 결과....

이상없음~!!!

이로서 파일/폴더 관리 및 생성이 가능해졌다...

정말 대단하군.. @0@)/~

ZOrder 및 Window Frame을 구현한 간단한 윈도우 시스템을 구현했다.
정말 아주 간단한... ㅡ_ㅡa.. 그냥 윈도우 그리고 이동시켰을 때 처리 정도만
해놓은 버전...

나름대로 잘 동작해서 흐믓하다.
일단 윈도우 API와 비슷하게 구현했다.

그럭저럭 만족~ ㅎㅎ

사용자 삽입 이미지
Interrupt, Touch Screen, Button을 이용해서 간단한 메모장을 만들었다.

크으... 뭐 쉽진 않았지만... 기본적인 부분들은 어느정도 Library에서
구현 되어있었기때문에, 스펙을 보면서 구현하다가 잘 안되면 소스 뒤져서 확인하는 방식으로
진행했다.

여튼 나름 괜찮게 된다는거 ㅋㅋ
MicroSD 접근용 IO Interface 소스

출처 : http://chishm.drunkencoders.com/libfat/

libfat

A FAT library for the Nintendo GBA and DS

This is the successor to GBA NDS FAT. It features better reentrancy support, cleaner source code and is built as a proper library.

Installation

libfat is packaged as part of DevkitPro. Download the DevkitPro Updater and run it to start the installation. You will need to install as a minimum DevkitARM r20, libnds and libfat. I also suggest you install the GBA and NDS examples.

Using libfat in a project

The following assumes that you are using one of the example NDS templates.

The first step is adding libfat to the list of libraries. In the ARM9 Makefile (or the top level one if there is no specific ARM9 Makefile), look for the list of libraries. It should look like:

LIBS	:= -lnds9

Change this to:

LIBS	:= -lfat -lnds9

The order is important! Make sure that -lfat comes before -lnds9. The include directory will already be set, so you don't need to worry about this.

Next, you'll need to include fat.h in your main source file. Near the top of the file, insert the line:

#include <fat.h>

Before you can use any file functions, you'll need to initialise the library. You should only do this once within the execution of the program. Somewhere within the program's startup code, insert the line:

fatInitDefault();

This will initialise libfat and set the number of cached sectors to the default (8 on the DS, 2 on the GBA). It will also set libfat as the default stdio file device. If you prefer to use your own settings, use the line:

fatInit(cache_size, set_as_default);

In this case, cache_size is the number of sectors to store in the cache at any one time and if set_as_default is true it then libfat will be the default stdio file device.

Both fatInit and fatInitDefault return true if the library was successfully initialised and false otherwise.

That is all that's needed to get libfat running within your project.

Using files

Through the magic of DevkitARM and libfat, files can be openned like on any other POSIX system. Most of the functions in the stdio.h header should work. You do not need to worry about the cache. It will be taken care of, as long as you remember to close any open files before turning off the power.

Paths are separated by a forward slash -- / . Directories are specified by their path. The directory itself can be refered to as . and the parent as ... The root directory is simply / or /..

When libfat is not the default stdio device, you will need to refer to files and directories with a device specifier. This is done by using fat: before a path. You can also use a single digit in the device specifier, such as fat0: or fat1:. It is possible to use both slots at once on a DS. This is done by specifying the slot with a number. The full list of device specifiers is:

  • fat: -- the default device
  • fat0: -- same as fat:
  • fat1: -- the device in Slot-1 of the DS
  • fat2: -- the device in Slot-2 of the DS
  • fat3: -- a custom mounted device

To open a file called graphics.bin for reading within a directory called app_data located on the card in Slot-2, you would use:

FILE* test = fopen ("fat2:/app_data/graphics.bin", "rb");

If libfat is set as default, and you don't mind which slot the card is in, you could use:

FILE* test = fopen ("/app_data/graphics.bin", "rb");

If you are already in app_data (after a chdir("/app_data"), for example), you could use:

FILE* test = fopen ("graphics.bin", "rb");

Using directories

Directory functions do not follow POSIX standards. Custom functions are used for various reasons.

To add directory support to a project, you'll need to include <sys/dir.h>


To open a directory, use:

DIR_ITER* dp = diropen ("/directory/path/");

diropen returns NULL and sets errno on failure.


To iterate through a directory, use:

dirnext (dp, filename, &filestat);

dp is a previously openned directory, filename will be filled with the filename of the next file or directory, and filestat will be filled with the file's stats. If filestat is NULL, it won't be filled.

To start at the begining of a directory again, use:

dirreset (dp);

To close a directory, use:

dirclose (dp);

dirnext, dirreset, and dirclose all return 0 on success. If they fail for any reason, they will return -1 and set errno. dirnext will set errno to ENOENT if there are no file or directory names left in the directory.


The directory functions mkdir and chdir work as normal.

A quick file listing demo:

struct stat st;char filename[256]; // to hold a full filename and string terminator
DIR_ITER* dir;dir = diropen ("/");
if (dir == NULL) {
iprintf ("Unable to open the directory.\n");
}
else {
while (dirnext(dir, filename, &st) == 0) { // st.st_mode & S_IFDIR indicates a directory
iprintf ("%s: %s\n", (st.st_mode & S_IFDIR ? " DIR" : "FILE"),
filename);
}
}
허허... 이거 나원참....

ARM7쪽만 Touch Screen 쪽에 접근할 수 있어서 어찌 할까 고민중이었는데....
이런 대박이... ㅡ_ㅡa... libnds에서 이미 다 제공해 주는...

ARM7쪽 더미 코드를 둬서 이미 ARM9 쪽으로 IPC를 사용해서 넘기도록 되어있었다.
으으.... 그럼 일단 이건 그냥 쓰도록 하고...

ARM9쪽 코드를 우선적으로 libnds에 의존하지 않는 방향으로 수정하는게 나을듯도...
일단 그래 하던동...
반나절 삘삘 노력해서 겨우 16x16을 출력하도록 수정했다. ㅎㅎ

자모 다 넣고 완성형 한글을 넣어서 이제 잘나온다.
>ㅁ<)/~ 잇힝~ 좋구나아~

사용자 삽입 이미지
대단한걸.. @0@)/~

이거 완전 거의 Application을 짤 수 있도록 만들어놨네...

정말 대단.. @0@)/~
가에서 부터 힝까지만 있는 거였군....

계산하는 알고리즘이 0xb0a1을 0으로 하는 base를 사용하더라... ㅠ_ㅠ..

그럼 자음에 대한 폰트는 내가 만들어서 써줘야 하는건가?? ㅡ_ㅡa...

크윽... 뭔가 일이 커지는 듯한... 폰트 생성 툴이라도 만들던지 해야지 원....

앗싸~ 한글/영문 출력~~!!

아직 약간 좀 이상하긴 하지만 되긴 된다...

한 비트 때문에 삽질을 오만상 하긴 했지만.. ㅡ_ㅡa...

뭐 되긴 된다는거 ㅋㅋ


사용자 삽입 이미지

사이트를 돌다가 여기저기 들러서 스펙이랑
메모리 구조랑 보면서 이것 저것 했다...

개발에 대한 준비랄까...
뭐 일단 메모리 구조와 코어는 필수니까 열심히 보고 있는데...

보면 볼 수 록 괜찮다는 생각이 든다...
괜찮은 개발 Library도 있고... ㅜ_ㅜ

왠지 할일이 확~ 줄어든 듯 하기는 하지만...
기분은 참 좋은... ㅎㅎ

당분간 심심하지는 않겠구만 ㅋㅋ

+ Recent posts